[Tutor] I want some help with arrays...

Alan Gilfoy agilfoy at frontiernet.net
Thu May 17 23:51:07 CEST 2007

Ah, a simple concept. Good. :)
I'm already familiar in working with lists.

Here's a case of a simple two-dimensional array (the simplest  
possible), ran in the IDLE interpreter:

>>> array = [["1.1", "1.2"], ["2.1", "2.2"]]
>>> array[1[2]]

Traceback (most recent call last):
   File "<pyshell#22>", line 1, in <module>
TypeError: 'int' object is unsubscriptable
>>> array[1]
['2.1', '2.2']
>>> second_half = array[1]
>>> second_half[1]

When I nest the slices ( array[1[2]] ) I get that error message. When  
I define one variable as an index value of the array, and then  
index-value that, it works fine.

What's the deal?

More information about the Tutor mailing list