Re: howto remove the thousand separator

2013-04-19 Thread Duncan Booth
"pyth0n3r" wrote: > I came across a problem that when i deal with int data with ',' as > thousand separator, such as 12,916, i can not change it into int() or > float(). How can i remove the comma in int data? > Any reply will be appreciated!! > Parse it using the locale module, just be sure to

Re: Re: howto remove the thousand separator

2013-04-16 Thread pyth0n3r
Hi D'A, Thanks alot for your reply, it works for me perfectly. Best, Chen On Mon, 15 Apr 2013 02:57:35 +0800 "pyth0n3r" wrote: > float(). How can i remove the comma in int data? Any reply will be int(n.replace(',', '')) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.drui

Re: howto remove the thousand separator

2013-04-15 Thread Rotwang
On 15/04/2013 08:03, Steven D'Aprano wrote: On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: [...] (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. web archive?) The canonical (although possibly not the best) archive for c.l.p. is the python-list mailing list archive

Re: howto remove the thousand separator

2013-04-15 Thread Chris Angelico
On Mon, Apr 15, 2013 at 5:03 PM, Steven D'Aprano wrote: > On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: > >> On 15/04/2013 02:14, Steven D'Aprano wrote: >>> Strings are immutable. Consider building up a single string from four >>> substrings: >> >> Actually, I believe that CPython is optimise

Re: howto remove the thousand separator

2013-04-15 Thread Steven D'Aprano
On Sun, 14 Apr 2013 22:35:42 -0400, Roy Smith wrote: > In article , > Walter Hurry wrote: > >> On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: >> >> > There are actually a lot of optimizations done, so it might turn out >> > to be O(n) in practice. But strictly in the Python code, ye

Re: howto remove the thousand separator

2013-04-15 Thread Steven D'Aprano
On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: > On 15/04/2013 02:14, Steven D'Aprano wrote: >> On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: >> >>> On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano >>> wrote: On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: > cl

Re: howto remove the thousand separator

2013-04-14 Thread Ned Deily
In article , Rotwang wrote: > (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. > web archive?) http://dir.gmane.org/gmane.comp.python.general -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: howto remove the thousand separator

2013-04-14 Thread Roy Smith
In article , Walter Hurry wrote: > On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: > > > There are actually a lot of optimizations done, so it might turn out to > > be O(n) in practice. But strictly in the Python code, yes, this is > > definitely O(n*n). > > In any event, Janssen sho

Re: howto remove the thousand separator

2013-04-14 Thread Walter Hurry
On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: > There are actually a lot of optimizations done, so it might turn out to > be O(n) in practice. But strictly in the Python code, yes, this is > definitely O(n*n). In any event, Janssen should cease and desist offering advice here if he c

Re: howto remove the thousand separator

2013-04-14 Thread Rotwang
On 15/04/2013 02:14, Steven D'Aprano wrote: On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano wrote: On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: cleaned='' for c in myStringNumber: if c != ',': cleaned+=c int(clean

Re: howto remove the thousand separator

2013-04-14 Thread Chris Angelico
On Mon, Apr 15, 2013 at 11:14 AM, Steven D'Aprano wrote: > On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: >> What on earth makes you think that is an O(n**2) algorithm and not O(n)? > > Python *might* optimize the first concatenation, '' + 'fe', to just reuse > 'fe', (but it might not). L

Re: howto remove the thousand separator

2013-04-14 Thread Steven D'Aprano
On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: > On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano > wrote: >> On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: >> >>> cleaned='' >>> for c in myStringNumber: >>>if c != ',': >>> cleaned+=c >>> int(cleaned) >> >> due to b

Re: howto remove the thousand separator

2013-04-14 Thread Mark Janssen
On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano wrote: > On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: > >> cleaned='' >> for c in myStringNumber: >>if c != ',': >> cleaned+=c >> int(cleaned) > > due to being an O(N**2) algorithm. What on earth makes you think that is an

Re: howto remove the thousand separator

2013-04-14 Thread Steven D'Aprano
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 S

Re: howto remove the thousand separator

2013-04-14 Thread Mark Lawrence
On 14/04/2013 19:57, pyth0n3r wrote: Hi, I came across a problem that when i deal with int data with ',' as thousand separator, such as 12,916, i can not change it into int() or float(). How can i remove the comma in int data? Any reply will be appreciated!! Best, Chen Use the string replace

Re: howto remove the thousand separator

2013-04-14 Thread Mark Janssen
> I would do int(num.replace(',', '')) That's much more pythonic than my C-ish version Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: howto remove the thousand separator

2013-04-14 Thread D'Arcy J.M. Cain
On Mon, 15 Apr 2013 02:57:35 +0800 "pyth0n3r" wrote: > float(). How can i remove the comma in int data? Any reply will be int(n.replace(',', '')) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 788 2246 (Do

Re: howto remove the thousand separator

2013-04-14 Thread Mitya Sirenef
On 04/14/2013 02:57 PM, pyth0n3r wrote: Hi, > I came across a problem that when i deal with int data with ',' as thousand separator, such as 12,916, i can not change it into int() or float(). > How can i remove the comma in int data? > Any reply will be appreciated!! > > Best, > Chen > > > I

Re: howto remove the thousand separator

2013-04-14 Thread Mark Janssen
On Sun, Apr 14, 2013 at 11:57 AM, pyth0n3r wrote: > I came across a problem that when i deal with int data with ',' as thousand > separator, such as 12,916, i can not change it into int() or float(). > How can i remove the comma in int data? > Any reply will be appreciated!! cleaned='' for c in m