list of lists

Sharan Basappa sharan.basappa at gmail.com
Sun Jul 22 08:40:20 EDT 2018


Thanks. This works in my example. Can you tell me how this works?

> You can simply unpack the inner list:
> 
>     a, b = results[0]
> 
> 
> Iwo Herka
> 
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> 
> On 22 July 2018 11:47 AM, Sharan Basappa <sharan.basappa at gmail.com> wrote:
> 
> > ​​
> > 
> > I am using a third party module that is returning list of lists.
> > 
> > I am using the example below to illustrate.
> > 
> > 1 results = [['1', 0.99921393753233001]]
> > 
> > 2 k = results[0]
> > 
> > 3 print k[0]
> > 
> > 4 print k[1]
> > 
> > Assume the line 1 is what is returned.
> > 
> > I am assigning that to another list (k on line 2) and then accessing the 1st and 2nd element in the list (line 3 and 4).
> > 
> > How can I access elements of 1 and 0.99 without assigning it to another list?
> > 
> > 
> > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > 
> > https://mail.python.org/mailman/listinfo/python-list

Thanks


More information about the Python-list mailing list