howto remove the thousand separator

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Apr 14 20:29:16 EDT 2013


On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote:

> cleaned=''
> for c in myStringNumber:
>    if c != ',':
>      cleaned+=c
> int(cleaned)

Please don't write code like that. Firstly, it's long and bloated, and 
runs at the speed of Python, not C. Second, it runs at the speed of 
SLLLLOOOOOOOOOOWWWW Python, not fast Python, due to being an O(N**2) 
algorithm.

If you don't know what O(N**2) means, you should read this for an 
introduction:

http://www.joelonsoftware.com/articles/fog0000000319.html


-- 
Steven



More information about the Python-list mailing list