Home › Guides › Compare Two Lists: How to Find the Differences
You have two lists of names, email addresses, IDs or product codes, and you need to know what is in one but not the other. That is a list diff: it tells you what is unique to each list and what they share. This guide explains exactly what a list comparison produces, how it differs from the “diff” you may know from code, and the quickest ways to do it.
Comparing two lists gives you the same results as comparing two sets in mathematics. Take these two lists:
| List A | List B |
|---|---|
| apple, banana, cherry, date | banana, date, elderberry, fig |
The comparison gives you four answers:
| Result | Meaning | For this example |
|---|---|---|
| Only in A | In the first list, missing from the second | apple, cherry |
| In both | Present in both lists (the intersection) | banana, date |
| Only in B | In the second list, missing from the first | elderberry, fig |
| All items | Everything from either list, once each (the union) | apple, banana, cherry, date, elderberry, fig |
A single similarity score summarises how alike the lists are. The one used by Compare Lists is the Jaccard similarity: the number of items in both lists divided by the number of different items across both. Here that is 2 shared items out of 6 in total, or 33.3%. Identical lists score 100% and lists with nothing in common score 0%.
The word “diff” is also the name of a tool that compares two versions of a file line by line. It is easy to confuse the two, but they answer different questions:
| List diff | Text diff (such as the Unix diff command) | |
|---|---|---|
| Cares about order? | No. The same items in a different order are the same list. | Yes. Moved lines show up as changes. |
| Output | Items unique to each list, and items they share | Lines added, removed or changed, in position |
| Best for | Names, emails, IDs, SKUs, keywords | Versions of a document or source file |
If you only want to know which values are missing, you want a list comparison. If you want to see how a document changed from one edit to the next, you want a text diff.
Apple, apple and apple are treated as one item.Everything runs in your browser, so a list of customers or emails is never uploaded. A common first step is to remove repeats from each list with Remove Duplicates, and the comparison tool also reports duplicates inside each list for you.
When two lists seem to contain the same values but the comparison says they differ, the cause is almost always something invisible:
smith and smith are different text.Smith and SMITH differ unless you ignore case.007 and 7 are different text even though they look like the same number.Turning on the “ignore” options for case, spaces and leading zeros fixes most of these.
These commands work on two text files with one item per line.
| Where | Command |
|---|---|
| Linux or macOS | comm -23 <(sort a.txt) <(sort b.txt) prints lines only in a.txt. Use -13 for lines only in b.txt and -12 for lines in both. comm needs sorted input, which the sort calls provide. |
| PowerShell | Compare-Object (Get-Content a.txt) (Get-Content b.txt). Each result has a SideIndicator: <= means only in the first file and => means only in the second. |
Python’s sets do exactly the operations described above:
a = {"apple", "banana", "cherry", "date"}
b = {"banana", "date", "elderberry", "fig"}
print(a - b) # only in a: apple, cherry
print(a & b) # in both: banana, date
print(b - a) # only in b: elderberry, fig
print(a | b) # all items, once each
print(a ^ b) # in one list but not both
Sets ignore order and drop duplicates, just like a list comparison. Their printed order is not guaranteed, so sort the result if you need a stable order.
Comparing very large lists is not a problem for a browser tool or a script; it is a quick operation even with hundreds of thousands of items. If your lists live in spreadsheet columns, copy each column and paste it into the tool, or use the formulas in the Excel and Sheets guide.
A list diff compares two lists and shows which items are only in the first, which are only in the second and which appear in both. Unlike a text diff, it ignores the order of the items.
Paste them into Compare Lists as List A and List B. The tool shows items only in A, items only in B and items in both. In Excel you can use COUNTIF or XLOOKUP, and in Python you can subtract one set from the other.
Look at the “only in A” and “only in B” results. “Only in A” are the items in the first list that are missing from the second, and “only in B” is the reverse.
Put each list in a column and use a formula such as COUNTIF to check whether each value appears in the other column. Our Excel and Google Sheets guide shows the formulas step by step.
It depends on the tool. In Compare Lists, matching ignores case by default, so Apple and apple match, and the results keep the original spelling. You can switch it to case sensitive.
With Compare Lists, yes. The comparison runs in your browser and your lists are never uploaded to any server.