[issue37033] Dictionary defaults .get(), .pop(), .setdefault()

2019-05-24 Thread SilentGhost
Change by SilentGhost : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bu

[issue37033] Dictionary defaults .get(), .pop(), .setdefault()

2019-05-24 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: Hi @vykouk, Python evaluates arguments before calling functions so >>> dicti.get(key, dflt(key)) is equivalent to: >>> arg = dflt(key) >>> dicti.get(key, arg) Notive how dflt() is called before .get() This is how all functions work in Python, not just dict me

[issue37033] Dictionary defaults .get(), .pop(), .setdefault()

2019-05-24 Thread Vykouk
New submission from Vykouk : The methods .get(), .pop(), .setdefault() evaluate defaults even though the key already exists in the dictionary: # -*- coding: utf-8 -*- def deflt(x): print('\nKey', x, 'is not in the dictionary') return 'Default' dicti = {1:'one', 2:'two', 3:'three'} k