there is a list of
[['4', '45120'], ['52520', '52', '445', '778'], ['5785699', '789', '550000', '7'], ['89952', '8753', '7878', '8'], ['8', '8', '8', '8', '8', '255', '16']] How to convert all strings to numbers with one command?
there is a list of
[['4', '45120'], ['52520', '52', '445', '778'], ['5785699', '789', '550000', '7'], ['89952', '8753', '7878', '8'], ['8', '8', '8', '8', '8', '255', '16']] How to convert all strings to numbers with one command?
for this particular array:
In [89]: [list(map(int, x)) for x in lst] Out[89]: [[4, 45120], [52520, 52, 445, 778], [5785699, 789, 550000, 7], [89952, 8753, 7878, 8], [8, 8, 8, 8, 8, 255, 16]] PS this solution will not work if there is a deeper nesting - for such cases you can use the recursive function
Source: https://ru.stackoverflow.com/questions/608656/
All Articles