List of list, converting all strings to int, Python 3

后端 未结 4 898
难免孤独
难免孤独 2020-12-21 09:38

I am trying to convert all elements of the small lists in the big list to integers, so it should look like this:

current list:
list = [[\'1\',\'2\',\'3\'],[\         


        
4条回答
  •  情歌与酒
    2020-12-21 10:35

    You can use a nested list comprehension:

    converted = [[int(num) for num in sub] for sub in lst]
    

    I also renamed list to lst, because list is the name of the list type and not recommended to use for variable names.

提交回复
热议问题