Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Last active September 3, 2023 11:36
Show Gist options
  • Save TheMuellenator/d98dacca633022999f5368e693f02b5d to your computer and use it in GitHub Desktop.
Save TheMuellenator/d98dacca633022999f5368e693f02b5d to your computer and use it in GitHub Desktop.
Python Lists Coding Exercise Solution
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
@azwri
Copy link

azwri commented Feb 26, 2021

top_scores = sorted(scores, reverse=True)[:3]

@frkntkny
Copy link

scores = sorted(scores,reverse=True)
top_scores.append(scores[0])
top_scores.append(scores[1])
top_scores.append(scores[2])

:)

@alex-oneill
Copy link

scores.sort(reverse=True)
top_scores = scores[:3]

@akmalridhwan
Copy link

scores.sort(reverse=True)
for score in scores:
if len(top_scores) < 3:
top_scores.append(score)

@miguelmarzs
Copy link

scores.sort(reverse=True)
newscores = [scores[0],scores[1],scores[2]]
top_scores.extend(newscores)

@sudeep-hk
Copy link

len_list=len(scores)
scores.sort(reverse=True)
for i in range(len_list):
    if i==3:
        break
    top_scores.append(scores[i])

@griffinville
Copy link

scores.sort(reverse=True)
top_scores = [scores[0], scores[1], scores[2]]

@Dannysesi
Copy link

scores.sort(reverse=True)
top_scores = [scores[0], scores[1], scores[2]]

@katalystkat
Copy link

scores.sort(reverse=True)
for i in range(3):
top_scores.append(scores[i])

@Ayush0901
Copy link

scores.sort(reverse=True)
for i in range (0,3):
a = scores[i]
top_scores.append(a)

@MrXTheAnon
Copy link

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