3 number and dot..
Paul Hankin
paul.hankin at gmail.com
Wed Oct 31 19:38:07 EDT 2007
On Oct 31, 7:58 pm, Abandoned <best... at gmail.com> wrote:
> Hi..
> I want to do this:
> for examle:
> 12332321 ==> 12.332.321
>
> How can i do?
Short without being too unreadable:
def conv(x, sep='.'):
x = str(x)[::-1]
return sep.join(x[i:i + 3] for i in range(0, len(x), 3))[::-1]
Or more simple-mindedly...
def conv(x, sep='.'):
x, y = str(x), []
while x:
y.append(x[-3:])
x = x[:-3]
return sep.join(reversed(y))
--
Paul Hankin
More information about the Python-list
mailing list