List Comparator

Compare and diff two lists

List A
0 lines
List B
0 lines
Understanding List Comparison
TL;DR

List comparison applies set operations (union, intersection, difference) to two lists — useful for comparing server lists, user groups, or configs.

What is List Comparison?

List comparison takes two lists of items and applies set operations to determine what is common between them, what is unique to each, and what they look like combined. It answers the fundamental questions: what do these lists share? What is in one but not the other?

Unlike text diff (which preserves order and shows line-by-line changes), list comparison treats each list as a set — the order of items does not matter. This makes it ideal for comparing collections where position is irrelevant: user groups, server inventories, email lists, feature flags, or allowed IP addresses.

Set operations are one of the most practical tools in data analysis and system administration. They distill complex comparisons into simple, unambiguous results.

Set Operations

List comparison is built on four fundamental set operations:

Intersection (A AND B)

The intersection contains items that appear in both lists. This answers: “What do these lists have in common?”

List A: [alice, bob, charlie]
List B: [bob, charlie, diana]
Intersection: [bob, charlie]

Difference (A NOT B / B NOT A)

The difference contains items in one list but not the other. There are two directions:

Only in A: [alice]       (A minus B)
Only in B: [diana]       (B minus A)

The symmetric difference combines both directions — items in either list but not both.

Union (A OR B)

The union contains all unique items from both lists combined, with duplicates removed:

Union: [alice, bob, charlie, diana]

Summary Table

OperationSymbolResultQuestion Answered
IntersectionA AND BItems in bothWhat’s shared?
Difference (A-B)A NOT BItems only in AWhat’s missing from B?
Difference (B-A)B NOT AItems only in BWhat’s missing from A?
Symmetric DiffA XOR BItems in exactly oneWhat’s different?
UnionA OR BAll unique itemsWhat’s the complete set?

Practical Uses

Comparing User Groups

When migrating users between systems, compare the source and destination user lists:

  • Intersection: Users already migrated (present in both systems)
  • Only in source: Users still needing migration
  • Only in destination: Users that exist only in the new system (created directly, or orphaned accounts)

Server Inventory Auditing

Compare your expected server list (from configuration management) against the actual running instances (from cloud provider API):

  • Only in expected: Servers that should be running but are not (potential outage)
  • Only in actual: Servers running that are not in your inventory (shadow IT, forgotten instances, potential security risk)

Feature Flag Comparison

Compare feature flags between staging and production environments:

  • Only in staging: Features being tested but not yet released
  • Only in production: Features that might have been removed from staging but are still live

DNS Record Auditing

Compare DNS records from your authoritative server against a secondary or cached resolver:

  • Differences reveal propagation delays, stale records, or unauthorized modifications

Handling Duplicates and Case Sensitivity

Two important considerations when comparing lists:

Duplicates: Should [a, a, b] be treated as [a, b] (set behavior) or should duplicates be preserved? Set-based comparison deduplicates automatically. If duplicate counts matter (e.g., comparing inventory quantities), you need multiset (bag) operations instead.

Case sensitivity: Is “Alice” the same as “alice”? For usernames and identifiers, case usually matters. For display names and labels, case-insensitive comparison is often more appropriate. Most list comparison tools offer a toggle for this.

Common Use Cases

  • Access control auditing: Comparing authorized user lists between systems, environments, or time periods to detect unauthorized changes
  • Data migration validation: Verifying that all records from a source system exist in the destination after migration
  • Server fleet management: Comparing expected infrastructure against actual running resources to find drift
  • Mailing list management: Finding subscribers who are on one list but not another, for targeted campaigns or cleanup
  • Dependency analysis: Comparing package lists between environments (dev vs production) to identify missing or extra dependencies

Try These Examples

Two Overlapping Lists Valid

Intersection (in both): [charlie, diana]. Only in A: [alice, bob]. Only in B: [eve, frank]. Union (all unique): [alice, bob, charlie, diana, eve, frank]. The overlap is 2 out of 6 unique items.

List A: [alice, bob, charlie, diana] vs List B: [charlie, diana, eve, frank]
Identical Lists Valid

When both lists contain the same items, the difference sets are empty — nothing is only in A, nothing is only in B. The intersection equals the full list.

List A: [server1, server2, server3] vs List B: [server1, server2, server3]