By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,498 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

list looping error

P: n/a
i have created list x:
>>x = [(12, 22, 11), (13, 22, 33)]
and want to print each number in tuple
>>for i in x:
for j in i:
print j[0]

but I get this error. What does it means?
Traceback (most recent call last):
File "<pyshell#60>", line 3, in <module>
print j[0]
TypeError: 'int' object is unsubscriptable
Dec 29 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

What you really want to write is
for i in x:
for j in i:
print j

The outer loop iterates over the tuples in the list, while the inner
loop iterates over the elements of each tuple. So j (in your example)
is always an integer, and is therefore unsubscriptable, which is
exactly what the error message says.

Thomas Philips

Dec 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.