Skip to content

Instantly share code, notes, and snippets.

@FeezyHendrix
Created August 20, 2020 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FeezyHendrix/23b4fe33239226c84718aa8f66a8c620 to your computer and use it in GitHub Desktop.
Save FeezyHendrix/23b4fe33239226c84718aa8f66a8c620 to your computer and use it in GitHub Desktop.
Second Lowest Score Python
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