This community-built FAQ covers the “Top Score Sorter” code challenge in Python. You can find that challenge here, or pick any challenge you like from our list.

Top Discussions on the Python challenge Top Score Sorter

There are currently no frequently asked questions or top answers associated with this challenge – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this challenge. Ask a question or post a solution by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this challenge, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like () to up-vote the contribution!

def score_sorter(array, top_score):
# simulate a do...while loop
changed = True
while changed:
changed = False
for item in enumerate(array):
# check if the element is higher than the top score and remove it if true
if array[item[0]] > top_score:
del(array[item[0]])
continue
# this check is not necessary for the first element
if item[0] > 0:
# get the value of the previous element
previous = array[item[0]-1]
# get the value of the current element
current = item[1]
if current < previous:
# replace previous element with the current, change location
array[item[0]-1] = current
array[item[0]] = previous
# set the changed flag to true so the main loop starts again
changed = True
# return elements of array in reverse order
return array[::-1]
score_list = [1, 200, 2, 799, 3,, 3000, 9999, 13]
top = 1000
print(score_sorter(score_list, top))

And also did not implement your own sort algorithm. If memory serves, this challenge specifically states to not use a built sort algo. Give it another try and pass the tests. DM me when you are ready to swap out this one with a real one.

I was wondering why my loop doesn’t continue for all the numbers in the array. I’m only able to return a few of the scores before it stops, why is that?

def score_sorter(array, top_score):
x = []
for i in array:
a = max(array)
x.append(a)
array.remove(a)
return(x)
score_list = [1, 2, 3, 9999, 13, 45]
top = 10000
print(score_sorter(score_list, top))

I was able to pass the test using a combination of pop() and max(), but I am not sure why my first solution is not passing. Can anyone give me some insight? Thanks!

def score_sorter(array, top_score):
output = []
for i in range(top_score, 0, -1):
if i in array:
for j in range(array.count(i)):
output.append(array[array.index(i)])
return output
score_list = [1, 2, 3, 9999, 13]
top = 10000
print(score_sorter(score_list, top))

It seems like this question is also asking for a test to see if any scores in the array are greater than top_score. Not many solutions in this thread include that test, since the sample array only includes scores less than the top score. It seems to me the question is a little confusing and needs clarification.

def score_sorter(array, top_score):
# Write your code here
valid_scores = [score for score in array if score < top_score]
sorted_scores = []
for score in range(len(valid_scores)):
sorted_scores.append(max(valid_scores))
valid_scores.remove(max(valid_scores))
return sorted_scores
score_list = [1, 2, 3, 9999, 13, 9998, 9998, 101, 101, 101, 98]
top = 100
print(score_sorter(score_list, top))

def score_sorter(array, top_score):
arr = array
list = []
max = 0
for n in range(len(array)):
for i, j in enumerate(arr):
if j >= max:
max = j
arr.remove(max)
list.append(max)
max = 0
return list
score_list = [1, 2, 3, 9999, 13]
top = 10000
print(score_sorter(score_list, top))

def sort(inpot):
outpot=[]
for n in range(len(inpot)):
outpot.append(inpot[n])
i = len(outpot) - 1
while i >= 1 and outpot[i] <= outpot[i-1]:
temp = outpot[i]
outpot[i] = outpot[i - 1]
outpot[i - 1] = temp
i -= 1
return outpot
def score_sorter(array, top_score):
# Write your code here
a=(sort(array))
L = len(a)
for i in range(int(L / 2)):
n = a[i]
a[i] = a[L - i - 1]
a[L - i - 1] = n
return a
score_list = [1, 2, 3, 9999, 13]
top = 10000
print(score_sorter(score_list, top))

def score_sorter(array, top_score):
count = len(array)
reversed_list =
while len(reversed_list) != count :
for number in array :
if number == max(array) :
reversed_list.append(number)
array.remove(number)
elif number != max(array) :
continue

return reversed_list

score_list = [1, 2, 3, 9999, 13]
top = 1

print(score_sorter(score_list, top))

def score_sorter(array, top_score):
count = len(array)
reversed_list = []
while len(reversed_list) != count :
for number in array :
if number == max(array) :
reversed_list.append(number)
array.remove(number)
elif number != max(array) :
continue
return reversed_list
score_list = [1, 2, 3, 9999, 13]
top = 1
print(score_sorter(score_list, top))

def score_sorter(array, top_score):
for num in array:
for x in range(1, len(array)):
if array[x] > array[x-1]:
temp = array[x]
array.pop(x)
array.insert(x - 1, temp)
return array
score_list = [1, 2, 3, 9999, 13]
top = 10000
print(score_sorter(score_list, top))