Last active
July 16, 2023 16:52
-
-
Save sidisinsane/a3ef9938a6c53bfb523ae7318f4be3e1 to your computer and use it in GitHub Desktop.
Revisions
-
sidisinsane revised this gist
Jul 16, 2023 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,11 +9,10 @@ def dict_unique(dict): dict: A new dictionary with unique values. Example: >>> d = {'a': 1, 'b': 2, 'c': 1, 'd': 3, 'e': 2} >>> d_unique = dict_unique(d) >>> print(d_unique) {'a': 1, 'b': 2, 'd': 3} """ # Remove duplicate values unique_values = list(set(dict.values())) -
sidisinsane created this gist
Jul 16, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ def dict_unique(dict): """ Return a dictionary containing unique values from a given dictionary. Args: dict (dict): The input dictionary. Returns: dict: A new dictionary with unique values. Example: d = {'a': 1, 'b': 2, 'c': 1, 'd': 3, 'e': 2} d_unique = dict_unique(d) print(d_unique) # {'a': 1, 'b': 2, 'd': 3} """ # Remove duplicate values unique_values = list(set(dict.values())) # Create a new dictionary with unique values unique_dict = {key: value for key, value in dict.items() if value in unique_values} return unique_dict