Program 1
Tuple unpacking
Assign multiple values at once.
python
person = ("Alice", 30, "Engineer")
name, age, job = person
print(name, age, job)Topic 07 of 17
Immutable tuples and unique-element sets — when and why to use each.
Program 1
Assign multiple values at once.
person = ("Alice", 30, "Engineer")
name, age, job = person
print(name, age, job)Program 1
Union, intersection, difference.
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
print("Union:", a | b)
print("Intersect:", a & b)
print("Diff:", a - b)
print("Sym diff:", a ^ b)Program 2
Use a set to count distinct words.
text = "to be or not to be that is the question"
unique = set(text.split())
print("Unique words:", len(unique))Program 1
Intersect any number of lists.
lists = [[1,2,3,4], [2,3,5], [2,3,7,9]]
common = set(lists[0]).intersection(*lists[1:])
print(common)