I have a list called dict_list
containing a number of dictionaries with possible duplicates. My goal is not only to remove duplicates from a list of dicts but also to keep their count for each of remaining dictionaries, stored as a key:value (dupe_count:int
) pair.
Asked
Active
Viewed 79 times
1
-
can you provide us the code you have tried? – Maddy Oct 27 '16 at 12:51
-
@Mani currently I remove duplicates using `set()` as in solution I've attached a link to, but I have no idea how to modify key:value for unique dictionaries on the go. – Vasily Oct 27 '16 at 12:56
-
1The question you've linked removes duplicate dictionaries from a list, so that the input `[{'a': 123, 'b': 1234}, {'a': 3222, 'b': 1234}, {'a': 123, 'b': 1234}]` gives output `[{'a': 3222, 'b': 1234}, {'a': 123, 'b': 1234}]`. Can you explain how you want to change this? Are you looking to produce `Counter({(('a', 123), ('b', 1234)): 2, (('a', 3222), ('b', 1234)): 1})`, or `[{'a': 246, 'b': 2648}, {'a': 3222, 'b': 1234}]`? Please give sample input and expected output. – wildwilhelm Oct 27 '16 at 14:19