list of lists
sharan.basappa at gmail.com
Sun Jul 22 08:53:16 EDT 2018
On Sunday, 22 July 2018 18:15:23 UTC+5:30, Frank Millman wrote:
> "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
> > 3 print k
> > 4 print k
> > 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 returns the first inner list. There could potentially be more
> than one, in which case results would return the second one. Use
> len(results) to find out how many inner lists there are.
> results returns the first element of the first inner list.
> results returns the second element of the first inner list.
> Frank Millman
Thanks. I initially thought about this but did not know if this is legal syntax.
The following is the updated code taking into account what you suggested and the previous posted.
results = [['1', 0.99921393753233001]]
k = results
a,b = results
x = results
y = results
More information about the Python-list