You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
353 B
11 lines
353 B
1 year ago
|
def dict_sort(_dict, _sort_by='key', _reverse=False):
|
||
|
if _sort_by == 'key':
|
||
|
_result = sorted(_dict.items(), key=lambda x: x[0], reverse=_reverse)
|
||
|
else:
|
||
|
_result = sorted(_dict.items(), key=lambda x: x[1], reverse=_reverse)
|
||
|
_result_dict = dict()
|
||
|
|
||
|
for r in _result:
|
||
|
_result_dict[r[0]] = r[1]
|
||
|
return _result_dict
|