Hello,
The input is this:
My code is this:
The input is this:
Output:{'Accurate': ['exact', 'precise'], 'exact': ['precise'], 'astute': ['Smart', 'clever'], 'smart': ['clever', 'bright', 'talented']}
And the output is supposed to be this:Output:{'precise': ['accurate', 'exact'], 'clever': ['astute', 'smart'], 'talented': ['smart'], 'bright': ['smart'], 'exact': ['accurate'], 'smart': ['astute']}
Note that values of each key are sorted.My code is this:
def reverse_dictionary(input_dict): my_dict= {} for key, value in input_dict.items(): for string in value: my_dict.setdefault(string.lower(), []).append(key.lower()) output_dict={k:v for k,v in sorted(my_dict.items(), key=lambda item:item[1])} return output_dictBut this code is not producing the expected result. What am I missing here?
Larz60+ write Oct-27-2020, 04:37 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use bbcode tags on all future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use bbcode tags on all future posts.