Last active
September 3, 2023 11:36
-
-
Save TheMuellenator/d98dacca633022999f5368e693f02b5d to your computer and use it in GitHub Desktop.
Python Lists Coding Exercise Solution
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
def top_three(scores): | |
scores = scores | |
top_scores = [] | |
# Solution | |
scores.sort() | |
list_size = len(scores) | |
top_scores = [scores[list_size-1], scores[list_size-2], scores[list_size-3]] | |
# Leave this line alone | |
return top_scores |
scores.sort(reverse=True)
for score in scores:
if len(top_scores) < 3:
top_scores.append(score)
scores.sort(reverse=True)
newscores = [scores[0],scores[1],scores[2]]
top_scores.extend(newscores)
len_list=len(scores)
scores.sort(reverse=True)
for i in range(len_list):
if i==3:
break
top_scores.append(scores[i])
scores.sort(reverse=True)
top_scores = [scores[0], scores[1], scores[2]]
scores.sort(reverse=True)
top_scores = [scores[0], scores[1], scores[2]]
scores.sort(reverse=True)
for i in range(3):
top_scores.append(scores[i])
scores.sort(reverse=True)
for i in range (0,3):
a = scores[i]
top_scores.append(a)
scores.sort()
scores.reverse()
top_scores = [scores[i] for i in range(len(scores)) if i < 3]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scores.sort(reverse=True)
top_scores = scores[:3]