Why does my Python code throw a syntax error when formatting dictionary output