-1

Say I have a list of lists [[10,2,4.8,90],[7,1,41,5],[3,11,20,2]] and another empty list of lists [[],[],[],[]].

I want to check the min value in each position in each sub-list and add it to it's concordante position in the empty list. So for example compare 10, 7 and 3. It sees that 3 is the lowest in that position, so it adds it to the first position in the empty list. The same for the other items.

For the above example, I would want something like [[3],[1],[4.8],[2]]. How can I accomplish this?

BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33
PythonNoob
  • 65
  • 3

1 Answers1

2

Use a transpose operation, and then use min() on each row of the transposed list of lists:

[[min(row)] for row in zip(*data)]

This outputs:

[[3], [1], [4.8], [2]]
BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33