dictionary - Python: list of dictionaries, how to get values of a specific key for multiple items of the list? -
i have list of dictionaries like:
dict_list = [{'key1': 'dict1_value1', 'key2': 'dict1_value2', 'key3': 'dict1_value3'}, {'key1': 'dict2_value1', 'key2': 'dict2_value2', 'key3': 'dict2_value3'}, {'key1': 'dict3_value1', 'key2': 'dict3_value2', 'key3': 'dict3_value3'}, {'key1': 'dict4_value1', 'key2': 'dict4_value2', 'key3': 'dict4_value3'}, {'key1': 'dict5_value1', 'key2': 'dict5_value2', 'key3': 'dict5_value3'}]
getting value 'key3' second list item like:
dict_list[1]['key3'] dict2_value3
and code below returns items 2:4 list:
dict_list[1:3]
what if want values 'key3' multiple items list. like
dict_list[1:3]['key3']
something similar in matlab.
>>> [x.get('key3') x in dict_list[1:3]] ['dict2_value3', 'dict3_value3']
Comments
Post a Comment