In [12]: list1 = ('a','b','c')
In [13]: list2 = ('1','2','3')
In [14]: list3 = ('4','5','6')
In [15]: zip(list2, list3)
Out[15]: [('1', '4'), ('2', '5'), ('3', '6')]
In [16]: dict(zip(list1, zip(list2, list3)))
Out[16]: {'a': ('1', '4'), 'b': ('2', '5'), 'c': ('3', '6')}
In [17]: dict(zip(list1, zip(map(int, list2), map(int, list3))))
Out[17]: {'a': (1, 4), 'b': (2, 5), 'c': (3, 6)}
In [18]: dict(zip(list1, map(list, zip(map(int, list2), map(int, list3)))))
Out[18]: {'a': [1, 4], 'b': [2, 5], 'c': [3, 6]}
對於列出的任意號碼,你可以這樣做:
dict(zip(list1, zip(*(map(int, lst) for lst in (list2, list3, list4, ...)))))
或者,使值列表而不是元組,
dict(zip(list1, map(list, zip(*(map(int, lst) for lst in (list2, list3, list4, ...))))))
謝謝。這正是我需要的! – user1919 2013-04-05 12:50:19