Re: a question about list as an element in a tuple

2014-02-19 Thread Marko Rauhamaa
Marko Rauhamaa : > operator.add(x, y) [...] leaves x and y intact and must return a new > object. Well, if the addition doesn't modify x, the method can of course return x. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: a question about list as an element in a tuple

2014-02-19 Thread Marko Rauhamaa
John O'Hagan : > The weirdest part for me is this: > t = ([],) l = t[0] l is t[0] > True l += [1] t[0] += [1] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'tuple' object does not support item assignment > > Whether there is an error or not dep

Re: a question about list as an element in a tuple

2014-02-18 Thread John O'Hagan
On Mon, 16 Dec 2013 11:30:13 +0800 liuerfire Wang wrote: > Just like below: > > In [1]: a = ([], []) > > In [2]: a[0].append(1) > > In [3]: a > Out[3]: ([1], []) > > In [4]: a[0] += [1] > --- > TypeError

Re: a question about list as an element in a tuple

2013-12-15 Thread rusi
On Monday, December 16, 2013 9:27:11 AM UTC+5:30, Chris Angelico wrote: > On Mon, Dec 16, 2013 at 2:30 PM, liuerfire Wang wrote: > > TypeError: 'tuple' object does not support item assignment > > In [5]: a > > Out[5]: ([1, 1], []) > > no problem, there is an exception. But a is still changed. > >

Re: a question about list as an element in a tuple

2013-12-15 Thread Chris Angelico
On Mon, Dec 16, 2013 at 2:30 PM, liuerfire Wang wrote: > TypeError: 'tuple' object does not support item assignment > > In [5]: a > Out[5]: ([1, 1], []) > > no problem, there is an exception. But a is still changed. > > is this a bug, or could anyone explain it? It's not a bug, but it's a bit con

a question about list as an element in a tuple

2013-12-15 Thread liuerfire Wang
Just like below: In [1]: a = ([], []) In [2]: a[0].append(1) In [3]: a Out[3]: ([1], []) In [4]: a[0] += [1] --- TypeError Traceback (most recent call last) in () > 1 a[0] += [1] TypeEr

Re: A question about list

2006-10-17 Thread Larry Bates
Larry Bates wrote: > [EMAIL PROTECTED] wrote: >> Hello: >> Variable 'a' has the next values: >> [[1,1],[2,2]] >> and I want to take a to b as: >> [[1,1,'='],[2,2,'=']] >> How can I do this with only one line of instruction? >> Thanks!! >> > To copy a list use: > > b=a[:] > > -Larry Seems I may ha

Re: A question about list

2006-10-17 Thread rzed
[EMAIL PROTECTED] wrote in news:1161102973.920895.141500 @i42g2000cwa.googlegroups.com: > Hello: > Variable 'a' has the next values: > [[1,1],[2,2]] > and I want to take a to b as: > [[1,1,'='],[2,2,'=']] > How can I do this with only one line of instruction? > Thanks!! > b = [[x,y,'='] for (x,y

Re: A question about list

2006-10-17 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > Hello: > Variable 'a' has the next values: > [[1,1],[2,2]] > and I want to take a to b as: > [[1,1,'='],[2,2,'=']] > How can I do this with only one line of instruction? b = [item + ['='] for item in a] -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1

Re: A question about list

2006-10-17 Thread Larry Bates
[EMAIL PROTECTED] wrote: > Hello: > Variable 'a' has the next values: > [[1,1],[2,2]] > and I want to take a to b as: > [[1,1,'='],[2,2,'=']] > How can I do this with only one line of instruction? > Thanks!! > To copy a list use: b=a[:] -Larry -- http://mail.python.org/mailman/listinfo/python-l

Re: A question about list

2006-10-17 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote: > Hello: > Variable 'a' has the next values: > [[1,1],[2,2]] > and I want to take a to b as: > [[1,1,'='],[2,2,'=']] > How can I do this with only one line of instruction? > Thanks!! >>> a = [[1,1], [2,2]] >>> map( lambda x: x + ['='], a ) [[1, 1, '='], [2, 2, '=']] >>>

A question about list

2006-10-17 Thread pretoriano_2001
Hello: Variable 'a' has the next values: [[1,1],[2,2]] and I want to take a to b as: [[1,1,'='],[2,2,'=']] How can I do this with only one line of instruction? Thanks!! -- http://mail.python.org/mailman/listinfo/python-list