Michael Michael - 1 year ago 163
Python Question

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]

Answer Source

Use the map function(in py2):

results = map(int, results)

In py3:

results = list(map(int, results))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download