Complete the code to check if two variables refer to the same object using the identity operator.
result = (a [1] b) print(result)
The is operator checks if two variables point to the same object in memory.
Complete the code to check if two variables do NOT refer to the same object using the identity operator.
if x [1] y: print("Different objects") else: print("Same object")
The is not operator checks if two variables do NOT point to the same object.
Fix the error in the code to correctly check if two lists are the same object.
list1 = [1, 2, 3] list2 = list1 print(list1 [1] list2)
To check if two variables refer to the exact same list object, use is.
Fill both blanks to create a dictionary comprehension that includes only items where the key is not the same object as the value and the value is None.
filtered = {k: v for k, v in data.items() if k [1] v and v [2] None}The first blank uses is not to check keys and values are different objects. The second blank uses is to check if value is exactly None.
Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if the key is the same object as the value and the value is not None.
result = {k[1]: v for k, v in items if k [2] v and v [3] None}The first blank uses .upper() to convert keys to uppercase. The second blank uses is to check identity. The third blank uses is not to ensure value is not None.