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

Join 132,602 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 955 people online right now. 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 - 10: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 - 07:15 AM
Post #2


D.I.C Addict

Group Icon
Joined: 22 Mar, 2008
Posts: 557



Thanked 46 times

Dream Kudos: 25

Expert In: C/C++

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 offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:07AM

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