简体   繁体   中英

how to change list and tuple into dict in python?

how join tuple list a dict?

this is what i have:

[('a','b'),('c','d'),('e','f')]

and this is what i want:

{'a':'b','c':'d','e':'f'}

thanks!

Just pass the list into the dict constructor. As they are tuples, it will know how to create the dictionary.

l = [('a','b'),('c','d'),('e','f')]
d = dict(l)
dict([('a','b'),('c','d'),('e','f')]

应该做

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM