Python Challenge - Top Score Sorter

def score_sorter(array, top_score):

Write your code here

array.sort()
if array[-1] <= top_score:
array.reverse()
return array
else:
return “Score was higher than top possible score”
score_list = [1, 2, 3, 9999, 13]
top = 10000

print(score_sorter(score_list, top))

I have chosen to work on the array passed as argument instead of creating another one :ok_hand:

def score_sorter(array, top_score): for i in range(0, len(array)-1): for k in range(0, len(array)-1): if array[k] < array[i+1]: aux = array[i+1] array[i+1] = array[k] array[k] = aux """ Short way by using predefined methods: array.sort(reverse=True) return array """ return array score_list = [1, 2, 3, 9999, 13] top = 10000 print(score_sorter(score_list, top))

Hi everyone.

This was my solution to this challange:

def score_sorter(array, top_score): sorted_list = sorted(array, reverse=True) return sorted_list # Write your code here score_list = [1, 2, 3, 9999, 13] top = 10000 print(score_sorter(score_list, top))

man, you have to come up with your own algorithm, and not use ready-made built-in language functions

def score_sorter(array, top_score):

Write your code here

score_sort =
scores = array
while len(scores) > 0:
score_sort.append(max(scores))
index = scores.index(max(scores))
scores.pop(index)
#print(score_sort)
while max(score_sort) > top_score:
del score_sort[0]
return score_sort
score_list = [1, 2, 3, 9999, 13]
top = 10000

print(score_sorter(score_list, top))

def score_sorter(array, top_score):

Write your code here

f =
while len(array)>0:
for i in array:
if i == max(array):
f.append(max(array))
array.remove(i)
return f

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

print(score_sorter(score_list, top))

Here is my solution

def score_sorter(array,top_score):
  new_list = []
  for i in range(len(array)):
    maximum = (max(array))
    index = array.index(maximum)
    highest_score =  array.pop(index)
    if highest_score <= top_score:
      new_list.append(highest_score)

    
  return new_list

score_list = [1, 2, 3, 9999, 13]
top = 10000
print(score_sorter(score_list, top))

The white elephant in the room is how many submissions, above actually passed all the tests. We’ll never know.

def score_sorter(array, top_score): new_list = [] sorted_array = sorted(array) for i in range(len(sorted_array)): if sorted_array[i] <= top_score: new_list.insert(-1-i, sorted_array[i]) return new_list score_list = [1, 2, 3, 9999, 13] top = 10000 print(score_sorter(score_list, top))

image

def score_sorter(array, top_score):
  # Write your code here
  res = [ ]
  while array:
    res.append(max(array))
    array.remove(max(array))
    res += score_sorter(array, top_score)
  return res

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

print(score_sorter(score_list, top))

is this good enough guys

[codebyte]
My initial approach and an optimized version of the code:

def score_sorter(array, highest): array_copy = array for num in array_copy: if num > highest: array_copy.remove(num) array_copy.sort() print(array_copy) neg_array = [] for num in array_copy: neg_array.append(-num) neg_array.sort() new_array = [] for num in neg_array: new_array.append(-num) return new_array #TEST score_list = [1, 2, 3, 9999, 13] top = 10000 print(score_sorter(score_list, top)) #--------Optimized------- def score_sorter(array, highest): array_copy = [num for num in array if num <= highest] array_copy.sort() neg_array = [-num for num in array_copy] neg_array.sort() new_array = [-num for num in neg_array] return new_array #TEST score_list = [1, 2, 3, 9999, 13] top = 10000 print(score_sorter(score_list, top))

def score_sorter(array, top_score):
sort =
while len(array) != 0:
sort.append(max(array))
array.remove(max(array))
return sort

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

print(score_sorter(score_list, top))

This is way to complicated. I will try implementing an algorithm that goes through the list only once or something.

def score_sorter(array, top_score):
  # Write your code here
  return_list = []
  for score in array:
    if score > top_score:
      raise ValueError("Highest possible score exceeded.")
    else:
      for i in range(len(return_list)):
        if score > return_list[i]:
          return_list.insert(i,score)
          break
      else:
        return_list.append(score)
  return return_list
      


score_list = [1, 2, 3, 9999, 13]
score_list = [100, -22, 3, 9999, 122]
top = 10000

print(score_sorter(score_list, top))