0

I've never seen this before. The first 'for loop' skips over the second element in the list when it loops through. The end goal is to print out everyone in the list that is second to last. If that only leaves the person with the most as in this case, then it will print them out. In this case the result should be 'Shaheen' because all the second to lasts are the same and should be removed. Any ideas?

nested_list = [['Rachel', -50], ['Mawer', -50], ['Sheen', -50], ['Shaheen', 51]]


res = min(nested_list, key=lambda x: x[1])
for person in nested_list:
    if person[1] == res[1]:
        nested_list.remove(person)

res = min(nested_list, key=lambda x: x[1])
nested_list.sort()
for person in nested_list:
    if person[1] == res[1]:
        print(person[0])
Nicky Reds
  • 33
  • 6

0 Answers0