This is the continuation of the OP1 and OP2.
Specifically, the objective is to remove duplicates if more than one dict
has the same content for the key paper_title
.
However, the line throw an error if there inconsistency in the way the list
is imputed, such that if there is a combination of dict
and str
TypeError: string indices must be integers
The complete code which generates the aforementioned error is as below: -
from itertools import groupby
def extract_secondary():
#
test_list = [{"paper_title": 'This is duplicate', 'Paper_year': 2}, \
{"paper_title": 'This is duplicate', 'Paper_year': 3}, \
{"paper_title": 'Unique One', 'Paper_year': 3}, \
{"paper_title": 'Unique two', 'Paper_year': 3}, 'all_result']
f = lambda x: x["paper_title"]
already_removed = [next(g) for k, g in groupby(sorted(test_list, key=f), key=f)]
extract_secondary()
May I know which part of the code needs further tweaks? Appreciate any insight.
PS: Please notify me if this thread is being considered duplicate to OP1. However, I believe this thread merits its own existence due to the uniqueness of the issue.