Step 1: Create a list
This creates a list named data
with three elements: .
Step 2: Unpack the list into a set
Here:
- The unpacking operator * is used with the list data. It extracts the elements from the list.
- {*data, *data} means the unpacked elements of the list are inserted into a set twice. However:
- Sets in Python are unordered collections of unique elements.
- Even though the elements are unpacked twice, the set will only store one copy of each unique value.
Result:
Step 3: Print the set
The print statement outputs the set output:
Key Points to Remember:
- The unpacking operator * extracts elements from an iterable (like a list, tuple, or set).
- A set is a collection of unique elements, so duplicates are automatically removed.
- Even though *data is unpacked twice, the final set contains only one instance of each value.