Re: Is there a commas-in-between idiom?
- From: Ernesto García García <titogarcia_nospamplease_@xxxxxxxxx>
- Date: Sun, 05 Nov 2006 16:46:13 +0100
Tim Peters wrote:
More idiomatic as
if len(list) > 0:
and even more so as plain
if list:
print list[0],
for element in list[1:]:
print ',', element,
Do you really want a space before and after each inter-element comma?
No, but it was only an example. I usually go for string concatenation.
An often-overlooked alternative to playing with ",".join() is:
print str(list)[1:-1]
That's funny! Not that I like it more that the join solution, but funny nevertheless.
Thank you,
Ernesto
.
- References:
- Is there a commas-in-between idiom?
- From: Ernesto García García
- Re: Is there a commas-in-between idiom?
- From: Tim Peters
- Is there a commas-in-between idiom?
- Prev by Date: Re: forwarding *arg parameter
- Next by Date: Re: forwarding *arg parameter
- Previous by thread: Re: Is there a commas-in-between idiom?
- Next by thread: Re: Is there a commas-in-between idiom?
- Index(es):
Relevant Pages
|