1 Replies - 903 Views - Last Post: 12 July 2008 - 08:15 AM Rate Topic: -----

#1 under_grounda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-March 07

Write element in class like a two-dimensional array with [][] <PYTH

Posted 25 June 2008 - 11:24 AM

Hello i have a class for arrays and I want to access its elements with operator [][] for example: arr[1][1] = 10. It can be used arr[1] using the __setitem__ method but how can be done this for two indexes?
Is This A Good Question/Topic? 0
  • +

Replies To: Write element in class like a two-dimensional array with [][] <PYTH

#2 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: Write element in class like a two-dimensional array with [][] <PYTH

Posted 12 July 2008 - 08:15 AM

You can do this using an array of an array.

Suppose you have some array class called array:


# Array ar[0..1]
ar = array(2)

# Array ar[0][0..9]
ar[0] = array(10)

for x in range(0,10):
	ar[0][x] = x



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1