Reputation: 447
dictionary = {}
tabl = [('maint_id', 1003L), ('type', 'DB'), ('number', '102')]
for i in tabl:
dictionary{i[0]:i[1]}
print dictionary
It is giving me only the last key value pair in my dictionary. it is overwritting all the elements. what is wrong with this code.. any help
Upvotes: 1
Views: 115
Reputation: 336478
It's much easier:
dictionary = dict(tabl)
If order matters:
from collections import OrderedDict
dictionary = OrderedDict(tabl)
Upvotes: 6