Created
August 20, 2020 08:08
-
-
Save FeezyHendrix/23b4fe33239226c84718aa8f66a8c620 to your computer and use it in GitHub Desktop.
Second Lowest Score Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
# create a dictionary | |
d = {} | |
for _ in range(int(input())): | |
name = input() | |
score = float(input()) | |
# assing name as key and score as value in dictionary | |
d[name] = score | |
# assign values to a varible | |
dict_values = d.values() | |
# sort the values using set therefore no two value repeats itself | |
# and converts to a list of sorted scores | |
second_lowest_score = sorted(list(set(dict_values)))[1] | |
# create a variable that would hold the second lowest names | |
second_lowest = [] | |
# append the name if score equals the value | |
for key, value in d.items(): | |
if(second_lowest_score == value): | |
second_lowest.append(key) | |
# sort the names alphabetically | |
second_lowest.sort() | |
#print the names | |
for name in second_lowest: | |
print(name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment