Simon Forman schrieb:
On Aug 14, 8:22 pm, candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a
Mark Tolonen schrieb:
Gregor Lingl gregor.li...@aon.at wrote in message
news:4a87036a$0$2292$91cee...@newsreader02.highway.telekom.at...
Emile van Sebille schrieb:
On 8/14/2009 5:22 PM candide said...
...
What is the pythonic way to do this ?
I like list comps...
jj =
On Aug 14, 8:22 pm, candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with
I'm bored for posting this, but here it is:
def add_commas(str):
str_list = list(str)
str_len = len(str)
for i in range(3, str_len, 3):
str_list.insert(str_len - i, ',')
return ''.join(str_list)
--
http://mail.python.org/mailman/listinfo/python-list
Thanks to all for your response. I particularly appreciate Rascal's solution.
--
http://mail.python.org/mailman/listinfo/python-list
Dnia 15-08-2009 o 08:08:14 Rascal jonras...@gmail.com wrote:
I'm bored for posting this, but here it is:
def add_commas(str):
str_list = list(str)
str_len = len(str)
for i in range(3, str_len, 3):
str_list.insert(str_len - i, ',')
return ''.join(str_list)
For short
On 8/14/2009 5:22 PM candide said...
Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with thousands
separator.
What is the pythonic way to do this ?
For my part, i reach to this rather complicated code:
# --
def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)
# Test
for z in [75096042068045, 509,
What is the pythonic way to do this ?
For my part, i reach to this rather complicated code:
# --
def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)
# Test
for z in [75096042068045, 509,
Emile van Sebille schrieb:
On 8/14/2009 5:22 PM candide said...
...
What is the pythonic way to do this ?
I like list comps...
jj = '1234567890123456789'
,.join([jj[ii:ii+3] for ii in range(0,len(jj),3)])
'123,456,789,012,345,678,9'
Emile
Less beautiful but more correct:
Gregor Lingl gregor.li...@aon.at wrote in message
news:4a87036a$0$2292$91cee...@newsreader02.highway.telekom.at...
Emile van Sebille schrieb:
On 8/14/2009 5:22 PM candide said...
...
What is the pythonic way to do this ?
I like list comps...
jj = '1234567890123456789'
On Aug 14, 8:22 pm, candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with
ryles wrote:
On Aug 14, 8:22 pm, candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal
On Sat, Aug 15, 2009 at 4:06 PM, MRAB pyt...@mrabarnett.plus.com wrote:
ryles wrote:
On Aug 14, 8:22 pm, candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size
(except
possibly the last substring). I make the hypothesis the first slice is at
Brian wrote:
On Sat, Aug 15, 2009 at 4:06 PM, MRAB pyt...@mrabarnett.plus.com
mailto:pyt...@mrabarnett.plus.com wrote:
ryles wrote:
On Aug 14, 8:22 pm, candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a
given
On Aug 15, 6:28 pm, MRAB pyt...@mrabarnett.plus.com wrote:
for z in [75096042068045, 509, 12024, 7, 2009]:
print re.sub(r(?=.)(?=(?:...)+$), ,, z)
75,096,042,068,045
509
12,024
7
2,009
The call replaces a zero-width match with a comma, ie
En Fri, 14 Aug 2009 21:22:57 -0300, candide cand...@free.invalid
escribió:
Suppose you need to split a string into substrings of a given size
(except
possibly the last substring). I make the hypothesis the first slice is
at the
end of the string.
A typical example is provided by
15-08-2009 candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size
(except
possibly the last substring). I make the hypothesis the first slice is
at the end of the string.
A typical example is provided by formatting a decimal string with
15-08-2009 Jan Kaliszewski z...@chopin.edu.pl wrote:
15-08-2009 candide cand...@free.invalid wrote:
Suppose you need to split a string into substrings of a given size
(except
possibly the last substring). I make the hypothesis the first slice is
at the end of the string.
A typical example
19 matches
Mail list logo