Which fix removes the bug?
cfg = {'host': 'x'}
port = cfg['port']
- Read it safely:
cfg.get('port', 80) - Read it safely:
cfg.fetch('port', 80) - Wrap the dict in
list(cfg)first - Change the key to
cfg['Port']here
Bracket access raises KeyError for a missing key; get() returns a default.
Play Problem Solving ▸