The exercise frequency sort 'extra' test solutions work on my computer but not on checkio.
The checkio 'extra' tests change from day to day???
Because of this problem I can't finish the mission and see additional solution.
From: https://py.checkio.org/mission/sort-array-by-element-frequency/solve/
This is my code for the frequency sort:
def frequencysort(items):
listcountfrequency = []
listinterated = []
countfrequency = []
myziptuple = ()
sortedtuplerev =()
unzippedreversedtuple = []
unzippedrvsedtupleindex = []
free = True
#
create two lists: 1 - a list of the frequency of each itter
2 - a list of the itters
## if list_count only includes one then return same string
for i in items:
count_frequency = items.count(i)
list_count_frequency.append(count_frequency)
list_interated.append(i)
#if there is only one occurance of each i in list
# finds out if all the counts are the same in the list all()
if set(list_count_frequency) == {1}:
return items
## if items is empty return empty
if items == []:
return items
print(list_count_frequency)
print(list_interated)
zip up the two lists into a tuple
my_zip_tuple = list(zip(list_interated, list_count_frequency ))
print(my_zip_tuple)
#free = all(x == listcountfrequency[0] for x in listcountfrequency)
if all(x == listcountfrequency[0] for x in listcountfrequency)== False:
print('help')
#sort the tuple in reverse
sorted_tuple_rev =sorted(my_zip_tuple, key=lambda x: (x[1], x[0]), reverse = True)
print(sorted_tuple_rev)
# take reversed tuple and unzip it
unzipped_reversed_tuple = list(zip(*sorted_tuple_rev))
print(unzipped_reversed_tuple)
#get first list in unzipped tuple
unzipped_rvsed_tuple_index = unzipped_reversed_tuple[0]
print(unzipped_rvsed_tuple_index)
return unzipped_rvsed_tuple_index
Created at: 2019/09/04 15:33; Updated at: 2019/09/04 16:16