Python also has a built-in set type. Python sets (set
s) are usually written as comma-separated values
in curly braces. For example, {'alpha', 'bravo', 'charlie'}
is a set containing three strings.
Repeated values are ignored because a set cannot contain duplicate elements, and order is also ignored. For
instance, {2, 1, 1}
means the same thing as {1, 2}
.
The one exception to this syntax is the empty set, which is written set()
, a cast of nothing to a set,
because {}
already had a different meaning (an empty dictionary) by the time sets were added to
Python.
Python also has frozen sets (frozenset
s), which are like sets except that they are immutable.
Frozen sets cannot be written directly, but can be created by casting from another collection type. For example,
frozenset({'alpha', 'bravo', 'charlie'})
is a frozen set with three string elements. The empty frozen
set can be written frozenset()
.
Sets and frozen sets can only hold immutable elements, so mutable values like lists cannot be put into sets (though they can be converted to their immutable counterparts—e.g., tuples—and those counterparts can be put into a set).
Fill in the placeholders so that the actual outputs match the expected outputs.