Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
I'm using list(l) to copy the list, Tero uses l[:], but the idea is the same. Thanks a lot for your response and the hint. But do you just want all proper partitions of lst? Then this is much simpler: lst = [0, 1, 2] s = [(lst[:i], lst[i:]) for i in range(1, len(lst))] Ah, thanks a lot

Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
If you're familiar with C or C++, think of s as holding a pointer to x which in turn holds a pointer to l and r, so when you change l or r, x (and s indirectly) is still pointing to the same lists which by the AH - thanks a million -- that makes it crystal clear! [Python's apparent simplicity

Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
Thanks a lot for your response, too. Best regards, Gabriel. -- __ Life is so constructed that the event does not, cannot, will not match the expectation. (Charlotte Bronte)

Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
x = (list(l), list(r)) BTW: I prefer this syntax, because it makes the copy explicit, while l[:] seems to me more implicit ... Best regards, Gabriel. -- __ Life is so constructed that the event does not, cannot, will not match

Bug with lists of pairs of lists and append()

2007-09-28 Thread Gabriel Zachmann
Well, could some kind soul please explain to me why the following trivial code is misbehaving? #!/usr/bin/python s = [] l = [ 0 ] r = [0, 0] while r: x = (l,r) print x s.append( x ) l.append( r.pop(0) ) print s The output I get is: ([0], [0, 0]) ([0, 0],

Re: Bug with lists of pairs of lists and append()

2007-09-28 Thread TeroV
Gabriel Zachmann wrote: Well, could some kind soul please explain to me why the following trivial code is misbehaving? #!/usr/bin/python s = [] l = [ 0 ] r = [0, 0] while r: x = (l,r) print x s.append( x ) l.append( r.pop(0) ) print s The output I get is:

Bug with lists of pairs of lists and append()

2007-09-28 Thread Gabriel Zachmann
Well, could some kind soul please explain to me why the following trivial code is misbehaving? #!/usr/bin/python lst = [ 0, 1, 2 ] s = [] l = [ lst[0] ] r = lst[1:] while r: x = (l,r) print x s.append( x ) l.append( r.pop(0) ) print s The output I get is: ([0], [1, 2])

Re: Bug with lists of pairs of lists and append()

2007-09-28 Thread Paul Hankin
On Sep 28, 11:25 pm, Gabriel Zachmann [EMAIL PROTECTED] clausthal.de wrote: could some kind soul please explain to me why the following trivial code is misbehaving? lst = [ 0, 1, 2 ] s = [] l = [ lst[0] ] r = lst[1:] while r: x = (l,r) print x s.append( x ) l.append(

Re: Bug with lists of pairs of lists and append()

2007-09-28 Thread Jason M Barnes
On 9/28/07, Gabriel Zachmann [EMAIL PROTECTED] wrote: Well, could some kind soul please explain to me why the following trivial code is misbehaving? #!/usr/bin/python lst = [ 0, 1, 2 ] s = [] l = [ lst[0] ] r = lst[1:] while r: x = (l,r) print x s.append( x )