In this python dictionary program, we will remove a specified dictionary from a given list.
Steps to solve the program
- Take a list of dictionaries as input and create an empty list.
- Use for loop to iterate over the dictionaries in the list using the range() and len() functions.
- Use an if statement to add all the dictionaries to the empty list except the 4th dictionary.
- 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}]