list.pop and print doing funny things

Sells, Fred fred at adventistcare.org
Wed Sep 22 15:14:42 EDT 2004


If you're doing interactive python, l.pop() will print, whereas y=l.pop()
will not print.  I find life to be easier if I put even trivial stuff in a
file and execute it, FWIT

-----Original Message-----
From: Gordon Williams [mailto:g_will at cyberus.ca]
Sent: Tuesday, September 21, 2004 2:40 PM
To: python-list at python.org
Subject: list.pop and print doing funny things


An easy question....

Why do I get the x printed twice in the sample below? It is like print x is
being executed twice in each loop.


>>> l = [1,2,3,4]
>>> for x in l[:]:
...  print x
...  l.pop(l.index(x))
...  print l
...
1
1
[2, 3, 4]
2
2
[3, 4]
3
3
[4]
4
4
[]
>>>

Regards,

Gordon Williams

-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list