How to access elemenst in a list of lists?

Chris Angelico rosuav at gmail.com
Sun May 8 23:23:38 EDT 2011


On Mon, May 9, 2011 at 1:15 PM, Chris Roy-Smith
<chris_roysmith.nothere at internode.on.net> wrote:
> Just learning python.
> I can see that I can address an individual element of a list of lists by
> doing something like:
> row = list[5]
> element = row[3]
>
> But is there a way to directly address an entry in a single statement?

Yep!

element = list[5][3]

Everything's an expression, there's nothing special about something
that's stored in a variable. You can even use square brackets after a
function call that returns a list (which is very useful at times).

Chris Angelico



More information about the Python-list mailing list