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
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
===
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
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
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
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
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
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)
'
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