Click here to Skip to main content
15,665,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


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

Expected Outcome
[88, 90]

Actual Outcome
[('Siggy', 88), ('Irene', 90)]
Updated 6-Jun-20 5:39am

1 solution

Well that's what you coded. You need to take the result fields and split the numbers from the names.
answer = get_two_highest_marks(names_marks)
top_two = [num[1] for num in answer]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900