Convert tuple of tuples to a dictionary with key value pair
问题 I have the following tuple of tuples: tuples=((32, 'Network architectures', 5), (33, 'Network protocols', 5)) How could I turn it into a list of dictionary like this dict=[ {"id": 32, "name": "Network architectures", "parent_id": 5}, {"id": 33, "name": "Network protocols", "parent_id": 5}] 回答1: Using a list comprehension as follows. First create a list of keys which will repeat for all the tuples. Then just use zip to create individual dictionaries. tuples=((32, 'Network architectures', 5),