m1 = [[['64,56'], ['77,9'], ['3,55,44,22,11']]]
m2 = [[[64, 56], [77, 9], [3, 55, 44, 22, 11]]]
How do I go from "m1" to "m2"?
m1 = [[['64,56'], ['77,9'], ['3,55,44,22,11']]]
m2 = [[[64, 56], [77, 9], [3, 55, 44, 22, 11]]]
How do I go from "m1" to "m2"?
You can use (nested) list comprehension with split
:
lst = ['7', '4,9', '9,7', '5,44,9,8']
output = [int(num) for item in lst for num in item.split(',')]
print(output) # [7, 4, 9, 9, 7, 5, 44, 9, 8]
Combine elements into one string using join()
, then split()
and convert to int using map()
list(map(int,','.join(lst).split(',')))