Python Forum
Comparing items from 2 lists of dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparing items from 2 lists of dictionaries
#4
Since they're lists, does the order matter? Or are you just looking for the collection of names in one list to the collection of names in the other?

If order matters, you'd use zip().

for dictA, dictB in zip(ListA, ListB):
    if dictA['name'] == dictB['name']:
        # names are the same
        ...
    else
        # names at this position of the list are different
If order didn't matter, I'd make a set() of the names in both lists, then you could easily use set differences to see which names are in one but not the other.
Reply


Messages In This Thread
RE: Comparing items from 2 lists of dictionaries - by bowlofred - Sep-14-2020, 10:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  comparing 2 lists rwahdan 2 1,631 Jul-18-2021, 06:30 PM
Last Post: DeaD_EyE
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,387 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Comparing Items Different Data Frames With a WHILE Loop JoeDainton123 1 1,957 Jul-30-2020, 04:11 AM
Last Post: scidam
  Searching through Nested Dictionaries and Lists Dave_London 1 7,820 Jul-09-2020, 03:36 PM
Last Post: mrdominikku
  How to put the items of one list in new generated lists Bobbear 1 1,669 Jun-12-2020, 06:08 AM
Last Post: buran
  Compare Two Lists and Replace Items In a List by Index nagymusic 2 2,898 May-10-2020, 05:28 AM
Last Post: deanhystad
  Add items from one list to list of lists PUP280 5 2,993 May-05-2020, 03:47 PM
Last Post: PUP280
  putting 2 lists items side by side Jiwan 1 2,251 Apr-30-2020, 01:04 AM
Last Post: Larz60+
  Finding value in nested dictionaries with lists mart79 16 8,132 Mar-08-2020, 08:16 PM
Last Post: ndc85430
  Can't seem to figure out how to put all of the lists items from a loop into 1 list Cosmosso 4 2,795 Feb-21-2020, 02:40 PM
Last Post: Cosmosso

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020