Hello,

I am wondering if can do this:

Let say I have a list of lists. Each individual lists have a bunch of elements.
Now I would like to either get or set the first element of each
individual list. I could do a loop and/or list comprehension, but I
was wondering if it was possible with something like:

aList = [ [1,1,1], [2,2,2,], [3,3,3] ]
aList[:][0] = 10


If I print aList[:], I get the list with the nested sublists.

>>> aList[:]
[[1, 1, 1], [2, 2, 2], [3, 3, 3]]


But as soon as I introduce the [0], in an attempt to access the first
element of each sublist, I get the first sublist in its entirety:

>>> aList[:][0]
[1, 1, 1]


I would have hoped to get something like
[1, 2, 3]


Is this possible at all?

Thanks
Bernard
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to