list of lists
Frank Millman
frank at chagford.com
Sun Jul 22 08:44:59 EDT 2018
"Sharan Basappa" wrote in message
news:8e261f75-03f7-4f80-a516-8318dd138657 at googlegroups.com...
>
> 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?
>
As you say, results is a list of lists.
results[0] returns the first inner list. There could potentially be more
than one, in which case results[1] would return the second one. Use
len(results) to find out how many inner lists there are.
results[0][0] returns the first element of the first inner list.
results[0][1] returns the second element of the first inner list.
HTH
Frank Millman
More information about the Python-list
mailing list