I have a list of dictionary items that includes some duplicates. What I would like to do is iterate through this dictionary and pick out all of the duplicate items and then do something with them.
For example if I have the following list of dictionary:
animals = [
{'name': 'aardvark', 'value': 1},
{'name': 'badger', 'value': 2},
{'name': 'cat', 'value': 3},
{'name': 'aardvark', 'value': 4},
{'name': 'cat', 'value': 5}]
I would like to go through the list "animals" and extract the two dictionary entries for aardvark and cat and then do something with them.
for example:
duplicates = []
for duplicate in animals:
duplicates.append(duplicate)
The output I would like is for the list 'duplicates' to contain:
{'name': 'aardvark', 'value': 1},
{'name': 'cat', 'value': 3},
{'name': 'aardvark', 'value': 4},
{'name': 'cat', 'value': 5}
as always, any help is greatly appreciated and will hopefully go along way to me learning more about python.