I’m trying to learn python (with a VBA background).
I’ve imported the following function into my interpreter:
def shuffle(dict_in_question): #takes a dictionary as an argument and shuffles it
shuff_dict = {}
n = len(dict_in_question.keys())
for i in range(0, n):
shuff_dict[i] = pick_item(dict_in_question)
return shuff_dict
following is a print of my interpreter;
>>> stuff = {"a":"Dave", "b":"Ben", "c":"Harry"}
>>> stuff
{'a': 'Dave', 'c': 'Harry', 'b': 'Ben'}
>>> decky11.shuffle(stuff)
{0: 'Harry', 1: 'Dave', 2: 'Ben'}
>>> stuff
{}
>>>
It looks like the dictionary gets shuffled, but after that, the dictionary is empty. Why? Or, am I using it wrong?
You need to assign it back to stuff too, as you’re returning a new dictionary.