Convert all strings in a list to int

前端 未结 4 726
夕颜
夕颜 2020-11-22 01:49

In Python, I want to convert all strings in a list to integers.

So if I have:

results = [\'1\', \'2\', \'3\']

How do I make it:

4条回答
  •  情话喂你
    2020-11-22 02:30

    Use the map function (in Python 2.x):

    results = map(int, results)
    

    In Python 3, you will need to convert the result from map to a list:

    results = list(map(int, results))
    

提交回复
热议问题