Skip to content
Advertisement

Is it possible to index nested lists using tuples in python?

I just started with python and very soon wondered if indexing a nested list with a tuple was possible. Something like: elements[(1,1)]

One example where I wanted to do that was something similar to the code below in which I save some positions of the matrix that I will later need to access in a tuple called index.

JavaScript

It seems like a useful feature. Is there any way of doing it? Or perhaps a simple alternative?

Advertisement

Answer

Yes, you can do that. I wrote a similar example:

JavaScript

a c f h

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement