On Wed, Jul 08, 2020 at 11:32:32PM +1000, Chris Angelico wrote:
>>> T = [[11, 12, 5, 2], [15, 6, 10], [10, 8, 12, 5], [12, 15, 8, 6]]
>>> print(T[1, 2])
TypeError: list indices must be integers or slices, not tuple
If you want a helper function, it's not hard to write it:

def fetch(collection, indices):
   for index in indices:
       collection = collection[index]
   return collection

Job done. This doesn't belong on the list type, because you might want
the exact same behaviour starting with (or incorporating) a dict, or
any other type that can be subscripted.

Thank you. Great idea. Such function could be made default method for
any subscriptable. :-)

H.
PS: For dicts there is a better solution, Munch, munchify(),
    https://github.com/Infinidat/munch
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ROFOALBTTFB5BQ2MITHH4OZWYLXNH5ES/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to