A dictionary contains the pair of the keys & values (represents key : value), a dictionary is created by providing the elements within the curly braces ({}), separated by the commas.
We have a dictionary consisting of some key-value pairs. We will shuffle the values i.e. the position of keys will be constant but the values attached to the key will be changed randomly.
Example:
Original dictionary:
{'Indore': 2, 'Delhi' : 5, 'Mumbai' : 1, 'Manali' : 3, 'Patna': 8}
Shuffled dictionary:
{'Indore': 1, 'Delhi' : 8, 'Mumbai' : 5, 'Manali' : 2, 'Patna': 3}
Algorithm:
Program to shuffle values of dictionary in Python
Output:
RUN 1: Initial dictionary = {'Java': 4, 'Scala': 2, 'Python': 8, 'C++': 1, 'Javascript': 5} Shuffled dictionary = {'Javascript': 4, 'Scala': 1, 'Java': 2, 'C++': 8, 'Python': 5} RUN 2: Initial dictionary = {'C++': 1, 'Scala': 2, 'Javascript': 5, 'Java': 4, 'Python': 8} Shuffled dictionary = {'C++': 8, 'Scala': 1, 'Javascript': 2, 'Java': 5, 'Python': 4} RUN 3: Initial dictionary = {'C++': 1, 'Javascript': 5, 'Scala': 2, 'Java': 4, 'Python': 8} Shuffled dictionary = {'C++': 8, 'Javascript': 4, 'Scala': 2, 'Python': 1, 'Java': 5}need an explanation for this answer? contact us directly to get an explanation for this answer