what does int means for python ?

A

alefajnie

#!/usr/bin/env python

arr = [[0 for c in range(0, 10)] for r in range(0, 10)] #
10x10 array

arr[2,3] # throws TypeError: list indices must be
integers
arr[int(2), int(3)] # also throws TypeError: list indices must be
integers !
 
I

Irmen de Jong

alefajnie said:
#!/usr/bin/env python

arr = [[0 for c in range(0, 10)] for r in range(0, 10)] #
10x10 array

arr[2,3] # throws TypeError: list indices must be
integers
arr[int(2), int(3)] # also throws TypeError: list indices must be
integers !

try arr[2][3] instead.

basically your version is trying to index an array with a tuple argument (2,3).

--irmen
 
A

alefajnie

try arr[2][3] instead.

basically your version is trying to index an array with a tuple argument (2,3).

--irmen


oh, you're right.

btw, is any simple way to create multi-dimension array ?
any built-in function ?
 
C

castironpi

try arr[2][3] instead.
basically your version is trying to index an array with a tuple argument (2,3).

oh, you're right.

btw, is any simple way to create multi-dimension array ?
any built-in function ?

it is not clear that two-dim arrays are faster than hashes in all
implementations of Python, or in every general language, or if they're
the right symbol for your program.
a= { }
a[ 0, 1 ]= True
a[ 4, 0 ]= True
a[ 0, 1 ]
True

however, this one:

results in a KeyError. do you want a particular thing, or are you on
the clock?

if you want to define 'blanks', that takes time too. is it initally
empty?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top