3 number and dot..

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Wed Oct 31 22:58:52 CET 2007


On Wed, 31 Oct 2007 21:39:05 +0000, Abandoned wrote:

> On Oct 31, 10:50 pm, Roberto Bonvallet <rbonv... at gmail.com> wrote:
>> On 31 oct, 16:58, Abandoned <best... at gmail.com> wrote:
>>
>>
>>
>> > Hi..
>> > I want to do this:
>> > for examle:
>> > 12332321 ==> 12.332.321
>>
>> > How can i do?
>> >>> x = 12332321
>> >>> '.'.join(''.join(i for n, i in g) for k, g in
>> >>> groupby(enumerate(reversed(str(x))), lambda (n, i): n//3))[::-1]
>> '12.332.321'
>>
>> --
>> Roberto Bonvallet
> 
> I'm sorry but it give me error "no module named groupby" My python
> version is 2.51

from itertools import groupby

But don't re-invent the wheel. Use the locale module like Chris Mellon 
suggested.



-- 
Steven.



More information about the Python-list mailing list