Member 14855334 Ответов: 1

Получение двух самых высоких оценок из списков


I got a question with getting two highest number from lists and when I made a code and tested it, the actual outcomes is a bit different to what I was expected. I was expecting to get only numbers but and outcomes give names with numbers and even it comes with wrong numbers when I changed a #TEST. What should I do with them? Thank you.

What I have tried:

<pre lang="Python">import heapq
def get_two_highest_marks(names_marks_list):
    a = heapq.nlargest(2, names_marks_list)
    return a

#TEST

names_marks = [("Ian", 78), ("Siggy", 88), ("Andy", 68), ("Irene", 90), ("Gio", 59)]
top_two = get_two_highest_marks(names_marks)
print(top_two)


ожидаемый итог
[88, 90]


фактический результат
[('Siggy', 88), ('Irene', 90)]

1 Ответов

Рейтинг:
1

Richard MacCutchan

Ну, это то, что вы закодировали. Вам нужно взять поля результатов и разделить числа от имен.

answer = get_two_highest_marks(names_marks)
top_two = [num[1] for num in answer]
print(top_two)