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
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
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)
''
--
Jerry
--
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 ', '.join(d)
--
Paul Hankin
--
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 in Python
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 clearest I
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,Chris]
txt = ,
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 a more