Convert a list of dictionaries into a list of values.

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
  1. Take a list of dictionaries as input and create an empty list.
  2. Use for loop to iterate over dictionaries in the list.
  3. Get the value for the specified key in the dictionary using the get() function and add that value to the empty list.
  4. 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]

				
			

show keys associated with values in dictionary

find all keys in the provided dictionary that have the given value.

Leave a Comment