0

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?

abcd
  • 19
  • 1

2 Answers2

4

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]
hashcode55
  • 5,622
  • 4
  • 27
  • 40
0

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]
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97