Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,491 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,180 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



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

 
Reply to this topicStart new topic

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

under_grounda
post 25 Jun, 2008 - 11:24 AM
Post #1


New D.I.C Head

*
Joined: 29 Mar, 2007
Posts: 11


My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page


perfectly.insane
post 12 Jul, 2008 - 08:15 AM
Post #2


D.I.C Addict

Group Icon
Joined: 22 Mar, 2008
Posts: 514



Thanked 38 times
My Contributions


You can do this using an array of an array.

Suppose you have some array class called array:

CODE


# 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



User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 02:07PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month