Create solution_01.py

This commit is contained in:
lorendsnow 2023-08-04 10:30:26 -07:00 committed by GitHub
parent 48b194be16
commit f6723def83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,16 @@
from collections.abc import Callable
class SortedDict:
def __init__(self, _dict: dict, keyfunc: Callable) -> None:
self.unsorted = _dict
self.keyfunc = keyfunc
self._dict = self.sort()
def sort(self) -> dict:
sorted_list = sorted(self.unsorted.items(), key=self.keyfunc)
sorted_dict = {k:v for k, v in sorted_list}
return sorted_dict
def __repr__(self):
return repr(self._dict)