79515038

Date: 2025-03-17 15:43:43
Score: 1
Natty:
Report link

Here is the code:

from collections import defaultdict

li = [['a', 10], ['a', 20], ['a', 20], ['a', 40], ['a', 50], ['a', 60],
      ['b', 10], ['b', 20], ['b', 30], ['b', 40],
      ['c', 10], ['c', 10], ['c', 20]]

grouped = defaultdict(lambda: float('inf'))

for key, value in li:
    grouped[key] = min(grouped[key], value)

result = [[key, min_val] for key, min_val in grouped.items()]

print(result)

Output:

enter image description here

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Subir Chowdhury