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

Kent Johnson kent37 at tds.net
Fri May 18 00:01:42 CEST 2007


Alan Gilfoy wrote:
> 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>
>      array[1[2]]
> TypeError: 'int' object is unsubscriptable
>>>> array[1]
> ['2.1', '2.2']
>>>> second_half = array[1]
>>>> second_half[1]
> '2.2'
> 
> 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.

Use array[1][2] - the second element of the first element.

Kent


More information about the Tutor mailing list