Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created August 14, 2018 01:44
Show Gist options
  • Save luojiyin1987/942d11ad70c741de44ff0056cc579289 to your computer and use it in GitHub Desktop.
Save luojiyin1987/942d11ad70c741de44ff0056cc579289 to your computer and use it in GitHub Desktop.
如何把 tuple 轉成 dictionary
tlst = [('a1','b1','q1','p1'),
('a2','b2','q2','p2'),
('a3','b3','q3','p3')]
names = 'area brand question price'.split()
lst = [{name:value for name, value in zip(names, t)} for t in tlst]
print(lst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment