Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python parse comma-separated number into int [duplicate]

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?

like image 577
roryf Avatar asked Jun 01 '10 22:06

roryf


People also ask

How do you convert a string of numbers into a list of integers 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.


1 Answers

>>> a = '1,000,000' >>> int(a.replace(',', '')) 1000000 >>>  
like image 118
joaquin Avatar answered Oct 04 '22 05:10

joaquin