Sep-14-2020, 08:38 PM
Hey all,
I working with 2 json data sets, I've imported them into variables so that I now have 2 lists of dictionaries.
I need to check if the items in list A exist in list B. They aren't identical structures though but they do have a few things in common that I can test for, for example each dictionary has a value of name.
I've come up with this bit of code which works but I was wondering if there's a more elegant solution to this.
Any suggestions would be welcomed.
I working with 2 json data sets, I've imported them into variables so that I now have 2 lists of dictionaries.
I need to check if the items in list A exist in list B. They aren't identical structures though but they do have a few things in common that I can test for, for example each dictionary has a value of name.
I've come up with this bit of code which works but I was wondering if there's a more elegant solution to this.
exists = [] for i in listA: for j in listB: if (i['name'] == j['name']): exists.append(i)For the dictionaries that already exist the next step is populate another list with those excluded.
Any suggestions would be welcomed.