views:

96

answers:

1

How can I transform tuple like this:


(
    ('a', 1),
    ('b', 2)
)

to dict:


{
    'a': 1,
    'b': 2
}
+11  A: 

Dict constructor can do this for you.

dict((
    ('a', 1),
    ('b', 2)
))
Manoj Govindan
Ha, I thought tuple({'a': 1, 'b': 2}) would work vice versa, it gives a tuple of keys instead.
Wang Dingwei
@Wang Do mydict.items() to get tuple of keys and values.
Tony Veijalainen