Numeric slicing, iteration prob.
Oren Tirosh
oren-py-l at hishome.net
Wed Aug 7 00:33:31 EDT 2002
On Mon, Aug 05, 2002 at 01:48:45PM +0100, Duncan Smith wrote:
> Hello,
> Does anyone know of a cuter way of iterating over an index rather
> than building strings and using eval()? (Example below.) This will get more
> awkward when I need to do further slicing. eg. depending on the results
> returned I might need to generate t[1,:,3], t[:,1,3] etc.
>>> class Explain:
... def __getitem__(self, index): return index
...
>>> t=Explain()
>>> t[1,:,3]
(1, slice(None, None, None), 3)
>>> t[:,1,3]
(slice(None, None, None), 1, 3)
No need to eval() - generate the equivalent tuple and use it as index.
Oren
More information about the Python-list
mailing list