x
is a list, not a dictionary. You can iterate over list items and unpack tuples this way:
>>> x = [('the', 709), ('of',342), ('to',305)]
>>> for a, b in x:
... print '%s:%s' % (a, b)
...
the:709
of:342
to:305
If you want to make a dictionary from x
, just pass it to dict()
:
>>> d = dict(x)
>>> d
{'of': 342, 'the': 709, 'to': 305}
>>> for a, b in d.iteritems():
... print '%s:%s' % (a, b)
...
of:342
the:709
to:305
Note that dictionaries are unordered collections - don't expect items in order that you have inside x
.