Possible Duplicate:
How do I use Python to convert a string to a number if it has commas in it as thousands separators?
How would I parse the string 1,000,000
(one million) into it's integer value in Python?
The most Pythonic way to convert a list of strings to a list of ints is to use the list comprehension [int(x) for x in strings] . It iterates over all elements in the list and converts each list element x to an integer value using the int(x) built-in function.
>>> a = '1,000,000' >>> int(a.replace(',', '')) 1000000 >>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With