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