私はpythonを学ぼうとしています(VBAのバックグラウンドがあります)。
次の関数をインタープリターにインポートしました。
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
以下は私の通訳のプリントです。
>>> stuff = {"a":"Dave", "b":"Ben", "c":"Harry"}
>>> stuff
{'a': 'Dave', 'c': 'Harry', 'b': 'Ben'}
>>> decky11.shuffle(stuff)
{0: 'Harry', 1: 'Dave', 2: 'Ben'}
>>> stuff
{}
>>>
辞書がシャッフルされたように見えますが、その後、辞書は空になります。なんで?それとも、私の使い方が悪いのでしょうか?