You are viewing a single comment's thread. Return to all comments →
I learned through this problem that
sorts are guaranteed to be stable. That means that when multiple records have the same key, their original order is preserved.
https://docs.python.org/3.11/howto/sorting.html#sort-stability-and-complex-sorts
if __name__ == '__main__': s = input() occ_dict = {} for i in s: occ_dict[i] = occ_dict.get(i, 0) + 1 sorted_list1 = sorted(occ_dict.items(), key=lambda x: x[0]) sorted_list2 = sorted(sorted_list1, key=lambda x: x[1], reverse=True) for i in sorted_list2[:3]: print(*i)
Seems like cookies are disabled on this browser, please enable them to open this website
Company Logo
You are viewing a single comment's thread. Return to all comments →
I learned through this problem that
https://docs.python.org/3.11/howto/sorting.html#sort-stability-and-complex-sorts