Sets
If you're coming from another language
A Python set is the equivalent of Java’s HashSet or C#’s HashSet<T> —
an unordered collection with no duplicates. Literal syntax uses curly
braces, like a dict, but with just values instead of key-value pairs:
The duplicate "calculator" collapses automatically; a set can never
contain the same value twice. Note also there’s no guaranteed order — don’t
rely on a set printing or iterating in the order you added items.
Why use a set: fast membership checks and deduplication
Two things a set is genuinely good for:
This in check works on a list too
(as you saw earlier), but on
a set it’s effectively instant regardless of size, where a list has to
check items one by one. If you’re just checking “does this exist,” a set is
the right tool once the collection gets large.
Converting a list to a set() is the standard way to deduplicate it.
Basic set operations
A common use in agent code: requested & available tells you exactly which
requested tools actually exist.
What happens to duplicate values in a set literal like {"a", "b", "a"}?