Group Group Group Group Group Group Group Group Group

Shuffling a dictionary similar to an array

#1

Is there a way to shuffle a dictionary similar to the way we can shuffle an array?

#2

Not directly, because a dictionary is stored as a hash table.
You can make a copy of the keys as an array, though, and sort or shuffle that. You can use that to retrieve the dictionary entries in the order of the keys in the copy.

#3

Thanks, I was able to add a line to move its values to an array and then shuffled before reading it out as the dictionary. I hope that makes sense.

closed #4

This topic was automatically closed after 166 days. New replies are no longer allowed.