retrieve item from nested list given index tuple
Alan G Isaac
alan.isaac at gmail.com
Fri Aug 14 11:54:54 EDT 2009
`lst` is a nested list
`tpl` is the indexes for an item in the list
What is the nice way to retrieve the item?
(Speedy access is nice.)
I don't want to use NumPy, but I'd like somehow
to avoid an explicit loop. I did consider using
eval. E.g., eval('lst' + '[%d]'*len(tpl)%tpl).
It works but seems rather ugly. I kind of like
reduce(list.__getitem__, tpl, lst) but the
reliance on reduce remains controversial enough
to see i removed from the Python 3 built-ins ...
Thanks,
Alan Isaac
More information about the Python-list
mailing list