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
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
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):
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
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
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
> 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
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
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
]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
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:
>
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:
>
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
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))
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
15 matches
Mail list logo