Computer Science
Write a Python program to sort a list alphabetically in a dictionary.
Python
Python List Manipulation
3 Likes
Answer
my_dict = eval(input("Enter the dictionary: "))
for key, value in my_dict.items():
value.sort()
print("Sorted dictionary:", my_dict)
Output
Enter the dictionary: {'list1': ['banana', 'apple', 'cherry'], 'list2': ['orange', 'grape', 'kiwi'], 'list3': ['pear', 'watermelon', 'mango']}
Sorted dictionary: {'list1': ['apple', 'banana', 'cherry'], 'list2': ['grape', 'kiwi', 'orange'], 'list3': ['mango', 'pear', 'watermelon']}
Answered By
2 Likes
Related Questions
Write a Python program to combine two dictionaries adding values for common keys.
d1 = {'a': 100, 'b': 200, 'c':300} d2 = {'a': 300, 'b': 200, 'd':400}
Sample output:
Counter({'a': 400, 'b': 400, 'c': 300, 'd': 400})
Write a Python program to find the three highest values in a dictionary.
Write a Python program to count number of items in a dictionary value that is a list.
Consider the following unsorted list:
105, 99, 10, 43, 62, 8.
Write the passes of bubble sort for sorting the list in ascending order till the 3rd iteration.