From db7a5bd20b73062fa4869f63faea7b8ea63548e2 Mon Sep 17 00:00:00 2001 From: Paras Date: Mon, 6 Jul 2020 19:17:01 -0400 Subject: [PATCH] Added basic outline of value sort function --- Dictionary_Manager.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Dictionary_Manager.py b/Dictionary_Manager.py index 4074d63..5d52b44 100644 --- a/Dictionary_Manager.py +++ b/Dictionary_Manager.py @@ -55,3 +55,37 @@ def sample_random_dictionary (self,K,indexed = False): return out_dict raise ValueError("Invalid parameter for indexed. Indexed can either be true or false only") + + + def value_sort_alphabetically (decending = False): + """ + Sorts the dictionary such that all values are alphabetically arranged + + Parameters: + decending : By default False. If True, follow an order from Z to A. If False, follow an order from A to Z + + Condition: + No key should have more than one value each + All values should be strings + """ + + # Implement the error handling + + # A to Z + if (decending == False): + values = list (self.in_dict.values) + values_sorted = sorted(values) + + new_dict = {} + + for value in values_sorted: + for key in self.in_dict: + if (self.in_dict[key] == value): + new_dict[key] = value + break + + return new_dict + + if (decending == True): + NotImplementedError() + \ No newline at end of file