In this python dictionary program, we will convert a list of dictionaries into a list of values corresponding to the specified key.
Steps to solve the program
- Take a list of dictionaries as input and create an empty list.
- Use for loop to iterate over dictionaries in the list.
- Get the value for the specified key in the dictionary using the get() function and add that value to the empty list.
- Print the output.
l1 = [{'name':'josh','age':30},{'name':'david','age':25},{'name':'virat','age':32}]
result = []
for x in l1:
result.append(x.get('age'))
print(result)
Output :
[30, 25, 32]