Is there a commas-in-between idiom?
Ernesto García García
titogarcia_nospamplease_ at gmail.com
Sun Nov 5 10:46:13 EST 2006
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
More information about the Python-list
mailing list