How to Fix Error - Dictionary Changed Size During Iteration

I am working on a program where i need to iterate through the dictionary and on occurrence of certain specific records, need to remove them from the dictionary.

As per my knowledge, i am performing the correct set of operations, in the correct sequence, but somehow getting runtime error as 

dict = {'X': 24, 'Y': 25, 'Z': 26}

for key in dict:
    if key == 'Y':
        del dict[key]
RuntimeError                              Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_25224/ in <module>
      1 dict = {'X': 24, 'Y': 25, 'Z': 26}
----> 3 for key in dict:
      4     print(key)
      5     if key == 'Y':

RuntimeError: dictionary changed size during iteration

Please advise, what is incorrect in this.