Re: 3 number and dot..
- From: elf <lucian.cancescu@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 21:10:26 -0000
On Oct 31, 9:58 pm, Abandoned <best...@xxxxxxxxx> wrote:
Hi..
I want to do this:
for examle:
12332321 ==> 12.332.321
How can i do?
Hi,
If you want to define your own function, no matter what the length of
the number is or what separator you want to choose, this will work:
def conv(s, sep='.'):
start=len(s)%3
last=start
result=s[0:start]
for i in range(start+1,len(s)):
if (i-start)%3==0:
if last==0:
result+=s[last:i]
else:
result+=sep+(s[last:i])
last=i
if last==len(s) or last==0:
result+=s[last:len(s)]
else:
result+=sep+s[last:len(s)]
return result
print conv('1234567890000000')
print conv('1')
print conv('123')
print conv('1234')
1.234.567.890.000.000
1
123
1.234
.
- References:
- 3 number and dot..
- From: Abandoned
- 3 number and dot..
- Prev by Date: Re: 3 number and dot..
- Next by Date: a few questions.
- Previous by thread: Re: 3 number and dot..
- Next by thread: Re: 3 number and dot..
- Index(es):