Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread MaHahaXixi
yes, i use the 2th way <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi > > The second style can be used: >j = range(20) > print j > L = [x for x in j if x > 10] > j = L > > There are another method such poping the item based on last index to 0: > for i in range(len(j)-1,

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread MaHahaXixi
yes. i understand now. but i use another trick. list is in vary size, so i do not wanna copy it. "Jim" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > MaHahaXixi wrote: > j = range(20) > print j > > > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] > >

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread MaHahaXixi
SORRY, my inattention "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "MaHahaXixi" <[EMAIL PROTECTED]> wrote: > > > for python, i am a newbie, but i did not found the warning of such usage > > from the python tutorial > > "4.2 for Statements" > > "It is not saf

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread Fredrik Lundh
"MaHahaXixi" <[EMAIL PROTECTED]> wrote: > for python, i am a newbie, but i did not found the warning of such usage > from the python tutorial "4.2 for Statements" "It is not safe to modify the sequence being iterated over in the loop (this can only happen for mutable sequence types,

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread MaHahaXixi
yes. i think it does so. it take me the whole afternoon to find out the bug (mine) i change: for i in range(len(j) -1, -1, -1): d = j[i] if d <= 10: j.remove(d) the real code is not so simple,so j[11:] will not work for me. but, i think phthon could found that i remove the current e

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread [EMAIL PROTECTED]
Hi The second style can be used: j = range(20) print j L = [x for x in j if x > 10] j = L There are another method such poping the item based on last index to 0: for i in range(len(j)-1,0-1,-1): if j[i]<=10: j.pop(i) print j Pujo -- http://mail.python.org/mailman/listinf

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread Jim
MaHahaXixi wrote: j = range(20) print j [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] for k in j: if k <= 10: j.remove(k) print j [1, 3, 5, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19] Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 Type "co

Re: how to explain such codes, python's bug or mine?

2005-04-13 Thread [EMAIL PROTECTED]
Hi, it is not python bug. You refer the list j and remove the element in the same time, that is the problem. Python dinamicaly goes to the next element with the same index but apply it in the new list. use this code instead: j = range(20) print j L = [x for x in j if x > 10] print L Sinc

how to explain such codes, python's bug or mine?

2005-04-13 Thread MaHahaXixi
>>> j = range(20) >>> print j [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> for k in j: if k <= 10: j.remove(k) >>> print j [1, 3, 5, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 Type