Dictionary to tuple
Tim Williams (gmail)
tdwdotnet at gmail.com
Tue Jun 28 10:59:11 EDT 2005
On 28 Jun 2005 14:45:19 GMT, Odd-R. <oddr at home.no.no> wrote:
> I have a dictionary, and I want to convert it to a tuple,
> that is, I want each key - value pair in the dictionary
> to be a tuple in a tuple.
>
> If this is the dictionary {1:'one',2:'two',3:'three'},
> then I want this to be the resulting tuple:
> ((1,'one'),(2,'two'),(3,'three')).
>
>>> d = {1:'one',2:'two',3:'three'}
>>> t = tuple([(k,v) for k,v in d.iteritems()])
>>> t
((1, 'one'), (2, 'two'), (3, 'three'))
>>>
More information about the Python-list
mailing list