Call int() function on every list element?
Solution 1:
This is what list comprehensions are for:
numbers = [ int(x) for x in numbers ]
Solution 2:
In Python 2.x another approach is to use map
:
numbers = map(int, numbers)
Note: in Python 3.x map
returns a map object which you can convert to a list if you want:
numbers = list(map(int, numbers))
Solution 3:
just a point,
numbers = [int(x) for x in numbers]
the list comprehension is more natural, while
numbers = map(int, numbers)
is faster.
Probably this will not matter in most cases
Useful read: LP vs map