What is the output of the following code ?
p = {0: 'x', 1: 'y', 2: 'z'} for i in p.values(): print(p[i])
0 x 1 y 2 z
x y z
0 1 2
Error
p.values() results in dict_values(['x', 'y', 'z'])
For the first iteration p[i] will be same as p['x].
As there is no key named 'x' for p, it will raise a KeyError: 'x'
Comment here: