Multi-dimension list

James Stroud jstroud at mbi.ucla.edu
Wed Dec 24 09:48:14 CET 2008


Steven Woody wrote:
> Hi,
> 
> In the book Python Essential Reference, Chapter 3, when talking about
> extended slicing, it gives an example:  a = m[0:10, 3:20].  But I
> don't understand how the 'm' was defined.  What should it looks like?

m could be an instance of the Krayzee class.

py> class Krayzee(object):
...   def __getitem__(self, i):
...     try:
...       r = ['WTF?' for j in i]
...     except:
...       r = 'WTF?'
...     return r
...
py> m = Krayzee()
py> m[1:2:3, 4:5:6]
['WTF?', 'WTF?']
py> m['your moms']
['WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?']


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com



More information about the Python-list mailing list