[Tutor] append question

Steven Buck buckstec at gmail.com
Mon Jul 6 00:57:42 CEST 2009

Hi Python Tutors:

I have a data structure that looks like:

>>> test=[[1,2,3],[4,5,6],[7,8,9]]

I want to define a new variable that captures the second element of each
sublist from above:

>>> testvar2 = []

Next I try to capture the aforementioned elements:

>>> for i in len(test):

I want testvar2 = [2,5,8] but instead I get the following error message:

Traceback (most recent call last):
  File "<pyshell#34>", line 1, in <module>
    for i in len(test):
TypeError: 'int' object is not iterable

Any insight would be appreciated.

Steven Buck
Ph.D. Student
Department of Agricultural and Resource Economics
University of California, Berkeley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090705/d2970ecf/attachment.htm>

More information about the Tutor mailing list