|
Note: do not shadow the built-in dict. This will one day come back to haunt you. Now, as for your issue, simply use dict.items: >>> d = {'A':1, 'B':2, 'C':'3'} >>> num_list = [1, 2,3 ] >>> for (key, value), num in zip(d.items(), num_list): ... print(key) ... print(value) ... print(num) ... A 1 1 C 3 2 B 2 3 >>>Note: Dictionaries aren't ordered, so you have no guarantee on the order of the items when iterating over them. Additional Note: when you iterate over a dictionary, it iterates over the keys: >>> for k in d: ... print(k) ... A C BWhich makes this common construct: >>> for k in d.keys(): ... print(k) ... A C B >>>Redundant, and in Python 2, inefficient. (责任编辑:) |
