Python Challenge - Top Score Sorter

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 (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 (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 (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

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:
      # 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))
def score_sorter(array, top_score):
  r = [*range(len(array) -1, -1, -1)]
  for i in range(len(array)):
    for j in r:
      if array[i] < array[j]:
        array[i], array[j] = array[j], array[i]
  return array

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

print(score_sorter(score_list, top))
def score_sorter(array, top_score): for i in range(1, len(array)): value = array[i] j = i - 1 while j >= 0 and value < array[j]: array[j + 1] = array[j] j -= 1 array[j + 1] = value return list(reversed(array)) score_list = [1, 2, 3, 9999, 13] top = 10000 print(score_sorter(score_list, top))

Now seeing other codes, mine is waay too simple :grimacing:

def score_sorter(array, top_score): sorted_ar = sorted(array, reverse=True) return sorted_ar score_list = [1, 2, 3, 9999, 13] top = 10000 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.