Re: formatting list -> comma separated (slightly different)

2008-07-21 Thread Niklas Norrthon
On 9 Juli, 22:25, Michiel Overtoom <[EMAIL PROTECTED]> wrote: > Paul & Robert wrote... > > d = ["soep", "reeds", "ook"] > >print ', '.join(d) > > soep, reeds, ook > > I occasionally have a need for printing lists of items too, but in the form: > "Butter, Cheese, Nuts and Bolts".  The last separator

Re: formatting list -> comma separated

2008-07-10 Thread norseman
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 ===

Re: formatting list -> comma separated (slightly different)

2008-07-09 Thread Duncan Booth
Michiel Overtoom <[EMAIL PROTECTED]> wrote: > I occasionally have a need for printing lists of items too, but in the > form: "Butter, Cheese, Nuts and Bolts". The last separator is the > word 'and' instead of the comma. The clearest I could come up with in > Python is below. I wonder if there is

Re: formatting list -> comma separated (slightly different)

2008-07-09 Thread egbert
On Wed, Jul 09, 2008 at 10:25:33PM +0200, Michiel Overtoom wrote: > Formatting a sequence of items such that they are separated by > commas, except the last item, which is separated by the word 'and'. > > For example: > > Three friends have a dinner: Anne, Bob and Chris row = ["Anne","Bob","Chri

Re: formatting list -> comma separated (slightly different)

2008-07-09 Thread Larry Bates
Michiel Overtoom wrote: Paul & Robert wrote... d = ["soep", "reeds", "ook"] print ', '.join(d) soep, reeds, ook I occasionally have a need for printing lists of items too, but in the form: "Butter, Cheese, Nuts and Bolts". The last separator is the word 'and' instead of the comma. The cleare

Re: formatting list -> comma separated (slightly different)

2008-07-09 Thread Michiel Overtoom
Paul & Robert wrote... > d = ["soep", "reeds", "ook"] >print ', '.join(d) > soep, reeds, ook I occasionally have a need for printing lists of items too, but in the form: "Butter, Cheese, Nuts and Bolts". The last separator is the word 'and' instead of the comma. The clearest I could come up with

Re: formatting list -> comma separated

2008-07-09 Thread Paul Hankin
On Jul 9, 8:23 pm, "Robert" <[EMAIL PROTECTED]> 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 ', '.jo

Re: formatting list -> comma separated

2008-07-09 Thread Jerry Hill
On Wed, Jul 9, 2008 at 3:23 PM, Robert <[EMAIL PROTECTED]> wrote: > given d: > d = ["soep", "reeds", "ook"] > > I want it to print like > soep, reeds, ook use the join() method of strings, like this: >>> d = ["soep", "reeds", "ook"] >>> ', '.join(d) 'soep, reeds, ook' >>> d = [] >>> ', '.join(d) '

formatting list -> comma separated

2008-07-09 Thread Robert
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