Complete the code to create a set with the numbers 1, 2, and 3.
my_set = [1]The curly braces {} create a set in Python. So {1, 2, 3} is a set with numbers 1, 2, and 3.
Complete the code to create an empty set.
empty_set = [1]Using set() creates an empty set. Curly braces {} create an empty dictionary, not a set.
Fix the error in the code to create a set from a list.
numbers = [1, 2, 3, 4] my_set = [1]
The set() function converts a list into a set. Using curly braces around the list creates a set with one element (the list itself), which is not allowed because lists are unhashable.
Complete the code to create a set of squares for numbers 1 to 5.
squares = { x**2 for x in range(1, 6) if x [1] 3 }The code creates a set of squares for numbers greater than 3. Curly braces with an expression create a set comprehension. The condition x > 3 filters numbers greater than 3.
Fill both blanks to create a set of uppercase letters from a list, filtering only letters after 'm'.
letters = ['a', 'b', 'm', 'n', 'z'] result = [ letter for letter in letters if letter [1] 'm' ] result = {x[2] for x in result}
The first line creates a list of letters after 'm'. The second line uses a set comprehension to convert each letter to uppercase. The .upper() method changes letters to uppercase.