> 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 matc
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)
> 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 simplici
> 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
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.app
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 )
>
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])
([
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
>
>
>
> T
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], [0])