Re: Is there a commas-in-between idiom?

2006-11-09 Thread Peter van Kampen
On 2006-11-08, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > At Wednesday 8/11/2006 16:51, Peter van Kampen wrote: > >>""" >>A = B = [] # both names will point to the same list >>""" >> >>I've been bitten by this once or twice in the past, but I have always >>wondered what it was useful for? Can a

Re: Is there a commas-in-between idiom?

2006-11-09 Thread Peter van Kampen
On 2006-11-08, Georg Brandl <[EMAIL PROTECTED]> wrote: > Peter van Kampen schrieb: >> On 2006-11-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >>> I've collected a bunch of list pydioms and other notes here: >>> >>> http://effbot.org/zone/python-list.htm >> >> """ >> A = B = [] # both names wil

Re: Is there a commas-in-between idiom?

2006-11-09 Thread Magnus Lycka
Ernesto García García wrote: > list = [1,2,3,4,5,6] Just a nit-pick: It's considered an anti-idiom to hide builtins just as list by using it as a name for a variable. >>> list=[1,2,3,4,5] >>> tuple = (1,2,3,4,5) >>> if list == list(tuple): print "equal" ... Traceback (most recent call last):

Re: Is there a commas-in-between idiom?

2006-11-08 Thread Gabriel Genellina
At Wednesday 8/11/2006 16:51, Peter van Kampen wrote: """ A = B = [] # both names will point to the same list """ I've been bitten by this once or twice in the past, but I have always wondered what it was useful for? Can anybody enlighten me? As an optimization, inside a method, you can bind

Re: Is there a commas-in-between idiom?

2006-11-08 Thread Georg Brandl
Peter van Kampen schrieb: > On 2006-11-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >> I've collected a bunch of list pydioms and other notes here: >> >> http://effbot.org/zone/python-list.htm > > """ > A = B = [] # both names will point to the same list > """ > > I've been bitten by this onc

Re: Is there a commas-in-between idiom?

2006-11-08 Thread Peter van Kampen
On 2006-11-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > I've collected a bunch of list pydioms and other notes here: > > http://effbot.org/zone/python-list.htm """ A = B = [] # both names will point to the same list """ I've been bitten by this once or twice in the past, but I have always w

Re: Is there a commas-in-between idiom?

2006-11-06 Thread Ernesto García García
> I've collected a bunch of list pydioms and other notes here: > >http://effbot.org/zone/python-list.htm Thank you for the suggestion. Ernesto -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a commas-in-between idiom?

2006-11-06 Thread Fredrik Lundh
Ernesto García García wrote: > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? I've collected a bunch of list pydioms and other notes here: http://effbot.org/zone/pytho

Re: Is there a commas-in-between idiom?

2006-11-05 Thread Ernesto García García
Tim Peters wrote: > More idiomatic as > >if len(list) > 0: > > and even more so as plain > >if list: > >>print list[0], >>for element in list[1:]: >> print ',', element, > > > Do you really want a space before and after each inter-element comma? No, but it was only an e

Re: Is there a commas-in-between idiom?

2006-11-05 Thread Tim Peters
]Ernesto García García] > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? > > > > list = [1,2,3,4,5,6] > > # the easy way > for element in list: >print element, ',', > > pr

Re: Is there a commas-in-between idiom?

2006-11-05 Thread Ernesto García García
Ernesto García García wrote: > Hi experts, > > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? > > > > list = [1,2,3,4,5,6] > > # the easy way > for element in list: >

Re: Is there a commas-in-between idiom?

2006-11-05 Thread James Stroud
Ernesto García García wrote: > Hi experts, > > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? > > > > list = [1,2,3,4,5,6] > > # the easy way > for element in list: >

Re: Is there a commas-in-between idiom?

2006-11-05 Thread Peter Otten
Ernesto García García wrote: > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? >>> items = [1, 2, 3, "many"] >>> print ", ".join(str(item) for item in items) 1, 2, 3, many Pe

Re: Is there a commas-in-between idiom?

2006-11-05 Thread Christian Joergensen
Ernesto García García <[EMAIL PROTECTED]> writes: > Hi experts, > > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? >>> list = [1,2,3,4,5,6] >>> print ','.join(map(str, list))

Is there a commas-in-between idiom?

2006-11-05 Thread Ernesto García García
Hi experts, it's very common that I have a list and I want to print it with commas in between. How do I do this in an easy manner, whithout having the annoying comma in the end? list = [1,2,3,4,5,6] # the easy way for element in list: print element, ',', print # this is what I really w