Quest just does not work.
https://py.checkio.org/mission/sort-array-by-element-frequency/solve/
My code: (it works properly)
def frequency_sort(items: list) -> list:
res = []
def ordered_set(items: list) -> list:
"""This function gets you list of unique ordered items from your origin list. It creates a copy"""
resulting = items[::] # this way you can make a copy of list, not just a link
popped = 0 # how many items we popped
for i in range(len(resulting)):
if i == 0:
continue
if resulting[i - popped] in items[0:i - popped]:
popped += 1
pop_index = i - popped + 1 # index of an item script gonna pop out
resulting.pop(pop_index)
return resulting
order_list = ordered_set(items)
# here we assemble the resulting list by the order from ordered_set func
for i in order_list:
for j in range(len(items)):
if items[j] == i:
res.append(items[j])
return res
Created at: 2021/10/09 20:38; Updated at: 2021/10/10 07:03