I have a list of list of tuples:
[[(1,0.99), (2,0.95)], [(2,0.97),(3,0.89),(1, 0.80)]]
From the above data how can I get the list of list such as:
[[1,2],[2,3,1]]
I have a list of list of tuples:
[[(1,0.99), (2,0.95)], [(2,0.97),(3,0.89),(1, 0.80)]]
From the above data how can I get the list of list such as:
[[1,2],[2,3,1]]
Another option is to use a more functional approach. Use operator.itemgetter to construct a callable object that fetches the initial item from a collection, and apply it to each row of the main list using map.
from operator import itemgetter
lst = [[(1,0.99), (2,0.95)], [(2,0.97),(3,0.89),(1, 0.80)]]
ig0 = itemgetter(0)
print([list(map(ig0, row)) for row in lst])
output
[[1, 2], [2, 3, 1]]