Complete the code to create a union of two sets.
set1 = {1, 2, 3}
set2 = {3, 4, 5}
result = set1 [1] set2
print(result)The | operator creates a union of two sets, combining all unique elements.
Complete the code to find the intersection of two sets.
a = {10, 20, 30}
b = {20, 40, 50}
common = a [1] b
print(common)The & operator finds the intersection of two sets, elements common to both.
Fix the error in the code to get the union of two sets.
set_a = {1, 2}
set_b = {2, 3}
union_set = set_a.[1](set_b)
print(union_set)The correct method to get the union of two sets is union().
Fill both blanks to create a dictionary with word lengths for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
word instead of length for values.The dictionary comprehension uses len(word) for values and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary of uppercase words with their lengths for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] result = [1]: [2] for w in words if len(w) [3] 3} print(result)
w.lower() instead of uppercase.The dictionary comprehension uses w.upper() as keys, len(w) as values, and filters words longer than 3 with >.