Re: Is there a commas-in-between idiom?



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
.



Relevant Pages

  • Re: If you love Christmas, thank a Pagan
    ... plain and simple. ... And early Christians (Circa 500 A.D.) had to associate him with the light. ... Funny how light pretty much opened up the world of physics. ...
    (rec.food.cooking)
  • Re: Beating a dead horse.
    ... lame scene in greensboro though. ... clothes five-o all over the lot. ... funny thing about the music is that it was about as basic as they ...
    (rec.music.phish)
  • Re: OT: ABC 9/11 film/Bryce Zabel connection
    ... Bryant of rec.arts.sf.tv.babylon5.moderated make plain: ... Hmmmm, so that's what I was doing 10 years ago. ...
    (rec.arts.sf.tv.babylon5.moderated)
  • Re: JSH: Use ratings
    ... tim peters wrote: ... |> it's somewhat strange if you claim to have paid attention to ... |> a sense of humor. ... on /first/ sight I thought everything he said was funny. ...
    (sci.math)
  • Re: ABC backs down on 9/11 movie
    ... Carved in mystic runes upon the very living rock, the last words of Greg ... Bryant of rec.arts.sf.tv.babylon5.moderated make plain: ... that's funny no matter which side of the issue you're on. ...
    (rec.arts.sf.tv.babylon5.moderated)