0

I have a list of lists and within each sublist there are tuples with the format (iD, volume). I need to keep the first element of each tuple and do away with the second while saving the new list of lists into binContents.

for example:

bins = [[(2, 22), (1, 13)], [(2, 22)], [(0, 20)]]
binContents = 

Desired outcome:

print(binContents)
[[2,1],[2],[0]]

*not a duplicate of How to make a flat list out of list of lists? because I do not intend on making a flat list, and that code with additional indexing did not give me my desired result

Jacob Myer
  • 479
  • 5
  • 22

1 Answers1

3

Here we go:

bins = [[(2, 22), (1, 13)], [(2, 22)], [(0, 20)]]
binContents = [[y[0] for y in x] for x in bins]
print(binContents)

This yields

[[2, 1], [2], [0]]
Jan
  • 42,290
  • 8
  • 54
  • 79