formatting list -> comma separated

Paul Hankin paul.hankin at gmail.com
Wed Jul 9 21:34:45 CEST 2008


On Jul 9, 8:23 pm, "Robert" <rw.seg... at xs4all.nl> wrote:
> given d:
>
> d = ["soep", "reeds", "ook"]
>
> I want it to print like
>
> soep, reeds, ook
>
> I've come up with :
>
> print ("%s"+", %s"*(len(d)-1)) % tuple(d)
>
> but this fails for d = []
>
> any (pythonic) options for this?

print ', '.join(d)

--
Paul Hankin



More information about the Python-list mailing list