Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array(list):
- def __getitem__(self, indices):
- current = super(self.__class__, self)
- for index in indices:
- current = current.__getitem__(index)
- return current
- a = Array([[[1,2,3],[4,5,6]],
- [[0,1,2],[9,8,7]]])
- print a[1,0,2] # 2
- class Array(list):class Array(list):
- def __mapItem(self, index):
- # we are creating a function in order to use map()
- # which does exactly the same thing as yours
- self.current = self.current.__getitem__(index)
- def __getitem__(self, indices):
- self.current = super(self.__class__, self)
- # map every index to the target item using the __mapItem function
- map(self.__mapItem, indices)
- return self.current
- a = Array([[[1,2,3],[4,5,6]],
- [[0,1,2],[9,8,7]]])
- print a[1,0,2] # 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement