Convert all strings in a list to int

Possible Duplicate:
How to convert strings into integers in python?
How to convert a string list into an integer in python

In python, I want to convert all strings in a list to ints.

So if I have:

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

How do I make it:

results = [1, 2, 3]

Use the map function(in py2):

results = map(int, results)

In py3:

results = list(map(int, results))

Use a list comprehension:

results = [int(i) for i in results]

eg

>>> results = ["1", "2", "3"]
>>> results = [int(i) for i in results]
>>> results
[1, 2, 3]
链接地址: http://www.djcxy.com/p/5446.html

上一篇: 在Python中将列表转换为元组

下一篇: 将列表中的所有字符串转换为int