Remove a specified dictionary from a given list.

In this python dictionary program, we will remove a specified dictionary from a given list.

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 the dictionaries in the list using the range() and len() functions.
  3. Use an if statement to add all the dictionaries to the empty list except the 4th dictionary.
  4. Print the output.
				
					A =  [ { 't20':50, 'odi':70 }, { 't20':40, 'odi':10 }, { 't20':30,'odi':0 }, { 't20':45, 'odi':65} ]
B = []
for i in range(len(A)):
    if i != 3:
        B.append(A[i])
        
print(B)
				
			

Output :

				
					[{'t20': 50, 'odi': 70}, {'t20': 40, 'odi': 10}, {'t20': 30, 'odi': 0}]
				
			

split a given dictionary of lists into list of dictionaries.

convert string values of a given dictionary, into integer/float datatypes.

Leave a Comment