ListFerret mascot

Home › Guides › Compare Two Lists: How to Find the Differences

How to Compare Two Lists and Find the Differences (List Diff Explained)

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.

The quick answer

What a list comparison produces

Comparing two lists gives you the same results as comparing two sets in mathematics. Take these two lists:

List AList B
apple, banana, cherry, datebanana, date, elderberry, fig

The comparison gives you four answers:

ResultMeaningFor this example
Only in AIn the first list, missing from the secondapple, cherry
In bothPresent in both lists (the intersection)banana, date
Only in BIn the second list, missing from the firstelderberry, fig
All itemsEverything 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%.

List diff versus text diff

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 diffText 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.
OutputItems unique to each list, and items they shareLines added, removed or changed, in position
Best forNames, emails, IDs, SKUs, keywordsVersions 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.

Compare two lists online

  1. Open Compare Lists and paste or drop your first list into List A and the second into List B. Each line is an item by default; you can split on commas, semicolons or tabs instead.
  2. Choose what counts as the same item. The matching options let you ignore case, extra spaces, leading zeros or punctuation, so Apple, apple and apple are treated as one item.
  3. Read the results: only in A, in both, only in B, all items, and the duplicates found inside each list. Copy any of them, or send a result back into one of the lists for another round.

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.

Why lists that look the same do not match

When two lists seem to contain the same values but the comparison says they differ, the cause is almost always something invisible:

Turning on the “ignore” options for case, spaces and leading zeros fixes most of these.

Compare two lists on the command line

These commands work on two text files with one item per line.

WhereCommand
Linux or macOScomm -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.
PowerShellCompare-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.

Compare two lists in Python

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.

Common questions about comparing lists

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.

Frequently asked questions

What is a list diff?

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.

How do I compare two lists for differences?

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.

How do I find items in one list that are not in another?

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.

How do I compare two lists in Excel?

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.

Is comparing two lists case sensitive?

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.

Is my data safe when I compare lists online?

With Compare Lists, yes. The comparison runs in your browser and your lists are never uploaded to any server.

Try it now: use the free Compare Lists - private, instant and runs in your browser. Open Compare Lists →

More guides

Share this page: XFacebookLinkedInRedditEmail