2つのリストからdictionaryを作る
超個人的メモ
ループを使用しなくても作れるのか...
下記のようにしたい場合
list1 = [key1, key2, ..., keyN]
list2 = [value1, value2, ..., valueN]
↓
dict = {key1: value1, key2: value2, ..., keyN: valueN}
$ipython-2.6 [~/work] Python 2.6.5 (r265:79063, Jul 24 2010, 18:10:03) Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: In [2]: questions = ['name', 'quest', 'favorite color'] In [3]: answers = ['lancelot', 'the holy grail', 'blue'] In [4]: dict(zip(questions,answers)) Out[4]: {'favorite color': 'blue', 'name': 'lancelot', 'quest': 'the holy grail'}