Reputation: 61
The situation is:
a1= ("5.6,13.16,19,23,24,25,26,29,30,31,32,34,35,36,49,50,51,54,60,65,67,74,75,76,77,81,86,87").replace (".",",")
#replace . with comma
print (a1)
5,6,13,16,19,23,24,25,26,29,30,31,32,34,35,36,49,50,51,54,60,65,67,74,75,76,77,81,86,87
Now, i would like insert a1 in the list of integer, like this:
[5,6,13,16,19,23,24,25,26,29,30,31,32,34,35,36,49,50,51,54,60,65,67,74,75,76,77,81,86,87]
Any suggestion?
Thanks
Upvotes: 0
Views: 38
Reputation:
You can just use the split like follows:
list = a1.split (",")
# convert elements to ints
li = []
for i in list:
li.append(int(i))
# print list as integers
print "li : ", li
Upvotes: 1
Reputation: 989
You could split up the string like and then convert each element in the list to integer if you need it as an integer string.
[int(a) for a in a1.split(',')]
Upvotes: 1