How to use the compare two lists
- Paste your first set of items into List A, one item per line.
- Paste your second set of items into List B.
- Toggle Ignore case if capitalization should not matter, and Trim whitespace to strip extra spaces.
- Read the results immediately below: only in A, only in B, shared items and the combined union.
How to compare two lists
To compare two lists, put one item per line in List A and List B, and read the four results: only in A, only in B, in both, and the union. Every result also shows how many items it holds.
- Paste the first list into List A and the second into List B. If you need to compare list A and B that sit in spreadsheet columns, copy each column; a pasted column arrives as one item per line.
- Keep Trim whitespace on so "bob " and "bob" match.
- Turn on Ignore case if "Bob" and "bob" should count as the same item.
- Read the results below the fields.
Worked example: List A is alice, bob, carol, dave, erin and List B is bob, dave, frank, grace. The tool returns only in A: alice, carol, erin (3 items), only in B: frank, grace (2 items), in both: bob, dave (2 items) and a union of 7 items. The same numbers come from Python sets: a - b, b - a, a & b and len(a | b).
With Ignore case on, List A Ann, Ben, Cy against List B ann, BEN, Dee gives only in A: Cy, only in B: Dee, in both: Ann, Ben (the spelling from List A), union of 4. With it off, no item matches and the union is 6.
How the list comparer works
This list comparer applies standard set theory to your text input. Each line becomes an element in a set, meaning duplicate lines within the same list are collapsed into one entry before any math happens.
The four operations mirror Python's built-in set methods:
- A minus B (relative complement): items in A that are not in B. In Python:
setA - setB. - B minus A: items in B that are not in A. In Python:
setB - setA. - Intersection: items appearing in both lists. In Python:
setA & setB. - Union: every unique item across both lists. In Python:
setA | setB.
For example, if List A contains red, blue, green and List B contains blue, yellow, red, then A minus B is green, B minus A is yellow, the intersection is red, blue and the union is red, blue, green, yellow. When you enable "Ignore case", the tool lowercases items with JavaScript's toLowerCase() for matching but returns them in their original casing from List A (or List B for items unique to B). This is simple lowercasing, not full Unicode case folding: "Straße" and "STRASSE" do not match, and a capital dotted "İ" does not match "i". Accented letters such as "É" and "é" do match.
Reference table of set operations
The table below summarizes what each operation returns when comparing two lists. Use it as a quick reference while working in this list comparison tool.
| Operation | Symbol | Python equivalent | Returns |
|---|---|---|---|
| Difference (A - B) | A \ B | A - B | Items only in A |
| Difference (B - A) | B \ A | B - A | Items only in B |
| Symmetric difference | A △ B | A ^ B | Items in A or B but not both (A-B plus B-A) |
| Intersection | A ∩ B | A & B | Items in both A and B |
| Union | A ∪ B | A | B | All unique items from A and B |
The symmetric difference is not shown as a separate output box here, but you can derive it by combining the "Only in List A" and "Only in List B" results.
Practical use cases
Comparing two lists comes up constantly in data work. Here are common scenarios where finding the list difference saves time:
- Email campaigns: paste your master subscriber list in A and your bounced addresses in B. The intersection tells you exactly who to remove.
- Inventory audits: compare the expected stock list against the counted stock to spot missing or extra items.
- Access control: check which users have permissions in system A but not system B during a migration.
- Code reviews: diff two lists of file paths or function names to see what was added or removed between versions.
If you need to reorganize your results after comparing, you can pass them through the alphabetize list tool. For converting delimited data into lines before comparing, try the CSV to list converter.
Common mistakes and edge cases
Even a straightforward list comparison tool can produce surprising results if the input data is messy. Watch out for these pitfalls:
- Trailing spaces: "apple " and "apple" are different strings. Leave "Trim whitespace" enabled unless you specifically need to detect spacing errors.
- Mixed casing: "Apple" and "apple" differ by default. Enable "Ignore case" for case-insensitive matching (simple lowercasing; "Straße" and "STRASSE" still differ).
- Blank lines: empty or whitespace-only lines are ignored, so a trailing newline never counts as an item.
- Duplicates within a single list: because the tool uses set logic, three copies of "cat" in List A count as one "cat". If you need frequency analysis rather than presence checks, a set-based comparer is the wrong approach.
- Unicode lookalikes: a Cyrillic "a" and a Latin "a" look identical but have different code points, so they will not match. This matters when merging data from international sources.
Verifying results with Python
You can double-check any output from this page using a short Python script. This script follows the same set logic as the page, with two differences noted below:
a = set(open('a.txt').read().splitlines())b = set(open('b.txt').read().splitlines())print('A - B:', a - b)print('B - A:', b - a)print('Intersection:', a & b)print('Union:', a | b)
Save your two lists as plain text files, run the script and compare the printed sets against the results shown here. The page also drops blank or whitespace-only lines and, with Trim whitespace on, strips each line, so to match it build the sets with {l.strip() for l in lines if l.strip()}, and add .lower() if Ignore case is on. Python prints sets in arbitrary order, while this page keeps first-appearance order. This cross-verification is useful when auditing critical data like financial records or server configurations.
Compare two lists in Excel
If you want to know how to compare two lists in Excel, the usual approach is to test each item of one column against the other column. Put List A in A2:A8 and List B in B2:B8. Microsoft states that COUNTIF criteria and MATCH are not case sensitive, which matches this tool with Ignore case turned on. Both also treat *, ? and ~ in a text criterion as wildcards, so an item such as a*b can match more than itself; this tool always compares items literally.
| Goal | Formula | What it does |
|---|---|---|
| Flag items of A missing from B | =COUNTIF($B$2:$B$8,A2)=0 | COUNTIF returns how many cells in B2:B8 meet the criterion A2; TRUE means zero matches, so the item is only in A. Fill down the column. |
| Label each item | =IF(ISNUMBER(MATCH(A2,$B$2:$B$8,0)),"In both","Only in A") | MATCH with match type 0 finds the first exactly equal value and returns #N/A if there is none; ISNUMBER turns a found position into TRUE. |
| Return the match or a default | =XLOOKUP(A2,$B$2:$B$8,$B$2:$B$8,"Only in A") | XLOOKUP defaults to exact match and returns the text you supply in its fourth argument when nothing is found. |
| List all items only in A | =FILTER(A2:A8,NOT(ISNUMBER(MATCH(A2:A8,B2:B8,0))),"None") | FILTER keeps the rows where the include array is TRUE and returns the if_empty text when nothing remains. |
| Remove repeats first | =UNIQUE(A2:A8) | Returns the unique values of the range. |
With the worked example above, the first formula returns TRUE for alice, carol and erin and FALSE for bob and dave, the same split this page shows. Swap the two ranges to find items only in B.
Microsoft's FILTER and UNIQUE pages list Excel for Microsoft 365, Excel 2021 and Excel 2024 and do not mention Excel 2016 or 2019. Its XLOOKUP page names Excel 2016 and 2019 in its version list but also says XLOOKUP is not available in those two versions, so treat XLOOKUP as unavailable there. MATCH is listed for Excel 2016 and 2019, and COUNTIF is a long-standing function. If your version lacks the newer functions, use the COUNTIF or MATCH column, or paste both columns into this page.
Compare two lists of usernames
A common job is comparing two lists of usernames, for example the accounts that follow you against the accounts you follow. Paste one list into List A and the other into List B, one username per line. The Only in List A result shows names that are in A but missing from B, and Only in List B shows the reverse. In both shows the overlap.
The tool compares text exactly as you paste it, so a name must be spelled the same in both lists to match. Turn on Ignore case if one export capitalizes names differently, and leave Trim whitespace on to ignore stray spaces. Where the lists come from depends on the service that exports them; this page does not connect to any account and never receives your data.
Compare two lists in Python
To compare two lists in Python, convert each list to a set and use the set operators. Python's tutorial describes a set as an unordered collection with no duplicate elements that supports union, intersection, difference and symmetric difference. That is why this page ignores order and repeated lines: a - b gives items in a but not in b, a | b items in either, a & b items in both and a ^ b items in one but not both. For lists, start with a = set(list_a) and b = set(list_b).
Worked examples
| Example | Input | Result |
|---|---|---|
| Fruits overlap | List A: Apple / Banana / Cherry / Date; List B: banana / Cherry / Fig / Grape; Ignore case: yes; Trim whitespace: yes | Only in List A (A - B): Apple Date; Only in List B (B - A): Fig Grape; In both (Intersection): Banana Cherry; All items (Union): Apple Banana Cherry Date Fig Grape |
| Numbers with duplicates | List A: 1 / 2 / 2 / 3 / 4; List B: 3 / 4 / 4 / 5 / 6; Ignore case: no; Trim whitespace: yes | Only in List A (A - B): 1 2; Only in List B (B - A): 5 6; In both (Intersection): 3 4; All items (Union): 1 2 3 4 5 6 |
| Whitespace sensitivity | List A: hello / world; List B: hello / world ; Ignore case: no; Trim whitespace: no | Only in List A (A - B): hello world; Only in List B (B - A): hello world ; In both (Intersection): (none); All items (Union): hello world hello world |
FAQ
Does this list comparer upload my data?
No. All comparisons happen locally in your browser using JavaScript. Nothing is sent to any server.
How are duplicate lines handled?
Each list is converted to a mathematical set before comparison, so duplicate lines within the same list are reduced to a single entry.
What does 'Ignore case' actually do?
It lowercases items with JavaScript's toLowerCase() to check for matches, but the output keeps the original casing from the list the item came from. It is not full Unicode case folding, so "Straße" and "STRASSE" are treated as different items.
Can I compare more than two lists at once?
This tool handles exactly two lists. To compare three or more, run pairwise comparisons: first compare A and B, then compare the result against C.
Why do my lists show no intersection even though the words look the same?
Hidden characters like trailing spaces, tabs or non-breaking spaces make strings unequal. Enable 'Trim whitespace' or clean the data first.
Is there a limit to how many items I can compare?
There is no hard limit. Performance depends on your device, but modern browsers handle tens of thousands of lines without issue.
What is the difference between list difference and symmetric difference?
The list difference (A minus B) shows items only in A. The symmetric difference combines A minus B and B minus A, showing everything that is not shared.
How can I compare two lists online?
Paste the first list into List A and the second into List B, one item per line. The results show items only in A, only in B, in both and the union, with a count for each. Nothing leaves your browser.
What is list comparison?
List comparison checks which items two lists share and which items appear in only one of them. The results are the intersection (in both), the differences (in one list only) and the union (in either).
How do I compare two lists in Excel?
Test each item of one column against the other with COUNTIF or MATCH, for example =COUNTIF($B$2:$B$8,A2)=0 flags items of A that are missing from B. In Excel versions that include FILTER, one formula can return all missing items. See the Excel section above.
How do I compare two lists in Python?
Turn each list into a set and use a - b for items only in a, b - a for items only in b, a & b for items in both and a | b for the union.
How do I find items in one list but not the other?
Read the Only in List A result for items in A that are not in B, and Only in List B for the reverse. Swap the lists to change the direction.
Does the order of my lists matter?
No. Items are matched by value, not position, and results keep the order in which each item first appears.
Sources and references
- Python tutorial: Data Structures, Sets: Sets are unordered collections with no duplicates; union, intersection, difference and symmetric difference operators.
- Microsoft: COUNTIF function: Syntax and case-insensitive criteria.
- Microsoft: MATCH function: Match type 0, case handling and the #N/A result.
- Microsoft: ISNUMBER function: Returns TRUE when the value is a number.
- Microsoft: XLOOKUP function: Syntax, if_not_found, default exact match, version availability.
- Microsoft: FILTER function: Syntax, if_empty argument, supported versions.
- Microsoft: UNIQUE function: Syntax and supported versions.