Complete the code to encode a simple integer using CBOR.
encoded = cbor2.dumps([1])The integer 42 is encoded directly as a number in CBOR. Using quotes would encode it as a string.
Complete the code to decode CBOR data back to a Python object.
decoded = cbor2.loads([1])The CBOR decoder expects bytes input. The bytes b'\x18\x2a' represent the CBOR encoding of 42.
Fix the error in the CBOR encoding of a dictionary.
encoded = cbor2.dumps([1])CBOR encodes dictionaries with keys as strings. Option D is a valid Python dict with string keys and integer values.
Fill both blanks to create a CBOR map comprehension filtering sensor data above 50.
{sensor: data[1] for sensor, data in readings.items() if data [2] 50}The comprehension squares the data value (using **2) and filters only those greater than 50.
Fill all three blanks to create a filtered CBOR map with uppercase keys and values above 30.
filtered = { [1]: [2] for [3], [2] in sensor_data.items() if [2] > 30 }The keys are converted to uppercase using sensor.upper(), values are 'value', and the loop variable is 'sensor'.