The Objective you are trying to do is not delete from a dictionary, but delete a dictionary from a list, you might already know this but the {}
is a dictionary and a []
is a list, therefore you have a []
list of dictionaries {}
giving you a [{}, {}]
and you want to delete one {}
dict from the []
, so you want a [{}]
instead of a [{}, {}]
in your case you want to go from:
[{'title': 'Get the newest iPhone 6', 'company': 'Apple', 'views': 389824}, {'title': 'Samsung Galaxy S2 out now!', 'company': 'Saumsung', 'views': 230123}]
to this (removing the apple ad):
[{'title': 'Samsung Galaxy S2 out now!', 'company': 'Saumsung', 'views': 230123}]
to do that you need to remove a dictionary (sorry if this is annoying since im bringing it up repeatedly but I am stressing on this point) and you would do that by making a new dict or re-initializing the dict to not contain the element, or pop the element out with the index. If you have the index of the ad then you can pop it out, if you dont then search for it and exclude it..
How you would pop it out:
video_ads_list.pop(0)
How you would exclude it:
video_ads_list = [x for x in video_ads_list if not x['title'] == "Get the newest iPhone 6"]
if I didnt get your question and it was to update a dict in the list then I would go for:
video_ads_list = [x if not x['title'] == "Get the newest iPhone 6" else updated_dict for x in video_ads_list]
Thank You!