Dictionaries can't find keys

OK. when I entered the MWE it works like yours, but when I insert it into my own program, it doesn’t work.