ThisCalculator

Everyday

Extract Common Values from Two Lists

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

This calculator finds the values that appear in both of two lists you provide, ignoring duplicates, and shows the result as a single list. You enter the first list and the second list (separated by commas), and you get the intersection list, plus the count of common values. It is a quick way to compare sets of numbers, names, or other text items without manual sorting.

Formula

The intersection of two sets A and B is written as A ∩ B and is defined as the set of elements that belong to both A and B. In plain terms, for each item in the first list, the calculator checks whether it also appears in the second list. If it does, the item is kept; if not, it is discarded. The result is then deduplicated, meaning each common value is listed only once, even if it appears multiple times in either input.

Symbolically: A ∩ B = { x | x ∈ A and x ∈ B }

Where:

  • A = the first list (set of items)
  • B = the second list (set of items)
  • x = an individual item
  • ∈ means “belongs to”

Worked Example

Using the default values from the calculator:

First list: 1, 2, 3, 4, 5
Second list: 3, 4, 5, 6, 7

Step 1: Take the first item from the first list, 1. Does 1 appear in the second list? No, so it is not common.

Step 2: Take 2. Does 2 appear in the second list? No.

Step 3: Take 3. Does 3 appear in the second list? Yes, so 3 is kept.

Step 4: Take 4. Yes, so 4 is kept.

Step 5: Take 5. Yes, so 5 is kept.

Result: the common values are 3, 4, 5, and the count is 3. The calculator shows “3, 4, 5” as the output and “3” as the count.

When to Use This

Finding common values between two lists is a frequent task in many everyday situations:

  • Comparing two guest lists to see who is invited to both events.
  • Checking which items appear in two shopping lists or inventory lists.
  • Finding overlapping interests between two people’s hobby lists.
  • Comparing two columns of data in a spreadsheet to identify duplicates.
  • Checking which numbers are common between two sequences.

The calculator works with any text or numeric values, as long as they are separated by commas. It treats “apple” and “apple” as the same, but “Apple” and “apple” as different, because it is case-sensitive. If you need case-insensitive comparison, convert both lists to the same case first.

How to Read the Result

The output is a comma-separated list of the values that appear in both input lists. The count tells you how many distinct common values exist. Note that if a value appears twice in the first list and once in the second, it is still listed only once in the result. This is the standard definition of set intersection.

If there are no common values, the output will be empty and the count will be 0. If one list is empty, the result is also empty, because there is nothing to match.

Common Mistakes and Limitations

One frequent mistake is expecting the calculator to preserve duplicates. For example, if the first list is “1, 1, 2” and the second is “1, 3”, the common value is just “1”, not “1, 1”. The calculator follows set theory, which ignores duplicates.

Another issue is case sensitivity. “John” and “john” are treated as different values. If you want to compare names or words without worrying about capitalization, you should normalize both lists to the same case before entering them.

Also, the calculator does not sort the output. The order of the common values follows the order they appear in the first list. If you need a sorted result, you can copy the output and sort it separately.

Finally, the calculator only works with exact matches. It does not do fuzzy matching or partial matches. For example, “apple” and “apples” are not considered common, even though they are similar.

Alternatives and Related Operations

If you need to find values that are in the first list but not the second (the difference), you can use a similar approach: keep only items that are not in the second list. If you need the union (all values from both lists combined, without duplicates), you would combine the lists and remove duplicates. If you need values that appear in only one of the lists (symmetric difference), you would find items that are in one list but not both.

For spreadsheet users, Excel and Google Sheets have built-in functions for this: MATCH, COUNTIF, or a conditional formatting rule to highlight duplicates. However, this calculator provides a quick, no-setup solution for a one-time comparison.

Frequently Asked Questions

What if my lists have spaces after commas?

The calculator trims leading and trailing spaces from each item, so “1, 2” and “1,2” are treated the same. However, spaces inside a value, like “New York”, are preserved as part of the value.

Can I compare lists of different lengths?

Yes, the lists can be any length. The calculator simply checks each item in the first list against the second list. If the first list is longer, it checks all of its items; if the second list is longer, it only matters that the items in the first list are found in it.

What if my values are numbers but with leading zeros, like “01” and “1”?

The calculator treats them as text, so “01” and “1” are different values. If you want them to be considered the same, convert both to plain numbers (remove leading zeros) before entering.

Does the calculator work with words that contain commas?

No, commas are used as separators. If a value contains a comma, like “New York, NY”, you would need to use a different separator, which this calculator does not support. In that case, consider replacing the comma inside the value with a semicolon or another character.

Why is the output not sorted?

The output preserves the order of the first list. This is intentional, because the order of the first list often carries meaning. If you need a sorted result, you can sort the output manually or use a tool that sorts automatically.

Can I use this to find common values between more than two lists?

This calculator only handles two lists. To find common values among three or more lists, you can perform the intersection step by step: first find the common values between list A and B, then find the common values between that result and list C, and so on.

Related

Formula used
in a | First list | - | 1, 2, 3, 4, 5 | 0
in b | Second list | - | 3, 4, 5, 6, 7 | 0
out common | Common values | - | intersect(a, b) | 0
out count | Number of common values | - | count(common) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.