私は、次の辞書actions = {'1': c1, '2': c2, '3': c3}
私が試した何Pythonではどのように2つのリスト(関数の1つともう1つの文字列)からなる辞書を作るのですか?
def c1():
print 'c1'
def c2():
print 'c2'
def c3():
print 'c3'
commands1 = ['1', '2', '3']
commands2 = [c1, c2, c3]
actions = {}
持っている必要があります。
for c1 in commands1:
for c2 in commands2:
actions = dict(zip(c1, c2))
をしかし、それはエラーにargument #2 must support iteration
'dict(zip(commands1、commands2))'を実行してください。 – vaultah
その時点で 'c2'は2番目のリストから1つのコマンドです。これは反復できません。 – jonrsharpe
また、各反復で変数 'actions'を上書きすると、ループすることはできません。 – ForceBru