formatting list -> comma separated

norseman norseman at hughes.net
Thu Jul 10 12:32:51 EDT 2008


Robert 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?
> 
> Robert
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
================================
the old fashion way would be:

d = ["soep", "reeds", "ook"]
if len(d) > 0:
   print ("%s"+", %s"*(len(d)-1)) % tuple(d)

# if d= []  then print stmnt bypassed



Steve
norseman at hughes.net



More information about the Python-list mailing list