Reputation: 19
I am trying to spilt the following list so that I can use it for further purposes: How to split ['1,1','2,2'] into [1,1,2,2] in python?
Upvotes: 0
Views: 72
Reputation: 49320
Join the list on ','
and then split it back up and map to integers:
>>> l = ['1,1', '2,2']
>>> list(map(int, ','.join(l).split(',')))
[1, 1, 2, 2]
Upvotes: 0
Reputation: 5860
This list comprehension would work -
s = ['1, 1', '2, 2']
print [int(j) for i in s for j in i.split(',')]
Output
[1, 1, 2, 2]
Upvotes: 4