Sep-27-2018, 11:12 AM
As you know the key names, you can use a simple dictionary comprehension with a for loop to step through the list.
For example,
For example,
list_ = [{'Name': 'Station1', 'Id':1}, {'Name': 'Station2', 'Id':5}, {'Name': 'Station3', 'Id':3}, {'Name': 'Station4', 'Id':9}, {'Name': 'Station5', 'Id':2}] new_dict = {dict_['Name']: dict_['Id'] for dict_ in list_} print(new_dict)
I am trying to help you, really, even if it doesn't always seem that way