Sets

21 articles
Interview Preparation Intermediate

12.21 Mini Projects

Four small set-based projects -- a duplicate log analyzer, an inventory comparator, a firewall rule comparator built on …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.20 Hands-on Exercises

Practice programs reinforcing Python set concepts -- a duplicate remover, a unique-visitor counter built on len(set(...)), and a package …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.19 Interview Questions

Frequently asked and scenario-based Python set interview questions covering set vs. frozenset, why {} is a dict and not a set, hashability, …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.18 Best Practices

When automatic deduplication and mathematical set operations make a set the right choice, why converting a checked-against collection to a …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.17 Common Mistakes

The most common set bugs -- writing {} and silently getting a dict instead of an empty set, putting an unhashable type like a list into a …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.16 Sets in DevOps

Five places sets are the natural fit in infrastructure code -- deduplicating IP addresses from logs, comparing installed vs. required …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.15 File Handling

Reading unique values directly into a set with a comprehension over file lines, sorting before writing since sets have no guaranteed order, …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.14 Common Algorithms

The set-based patterns behind removing duplicates, extracting unique elements, finding common items between two lists, and computing the …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.13 Performance

A time-complexity table for the core set operations, why a set uses more memory per element than a list or tuple, and a direct timeit …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.12 Set Comprehensions

The same comprehension syntax as list comprehensions, but with {} instead of [], automatically deduplicating the result -- basic, …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.11 Frozen Sets

frozenset -- the immutable counterpart to set -- same union/intersection/membership behavior, but no add(), remove(), or update(), which is …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.10 Traversing Sets

Visiting every element of a set with a for loop and with enumerate() -- and why the indices enumerate() produces are meaningless as …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.9 Built-in Functions

The same general-purpose sequence functions used with lists and tuples -- len, max, min, sum, sorted, any, all -- work identically on sets, …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.8 Set Methods

Method equivalents of union/intersection/difference/symmetric_difference, plus the relationship-testing methods with no operator form -- …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.7 Set Operators

Union (|), intersection (&), difference (-), and symmetric difference (^) as real mathematical set operations applied directly to Python …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.6 Set Indexing and Ordering

Why s[0] raises TypeError on a set -- elements are located by hash, not by integer position -- and why iteration order is an implementation …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.5 Removing Elements

remove() vs discard() -- the same removal, but one raises KeyError on a missing value and the other doesn't -- plus pop()'s …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.4 Adding Elements

add() for a single element that silently no-ops on a duplicate, update() for merging in one or more other iterables at once, and how that …

Jan 20, 2026 Read more
Interview Preparation Intermediate

12.3 Internal Representation

Why a set is a hash table internally -- how hash(element) determines a slot directly, why that's what makes membership testing O(1) average, …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.2 Creating Sets

Why an empty set must use set() instead of {}, set literals, the set() constructor's automatic deduplication, and building sets from lists, …

Jan 20, 2026 Read more
Interview Preparation Beginner

12.1 Introduction to Sets

What a set is, its core characteristics, why automatic deduplication and O(1) average membership testing are the entire reason it exists as …

Jan 20, 2026 Read more