Skip to content

Comment on Is there any good reason why no set method in Python dict?

Comments

''' if exists is False , will not overwrite current key if it's alreay there '''

...That's what `setdefault` does. It just also returns the value, which you're free to ignore. (The other version is what ordinary key assignment does.)

Also, that's really not a clear name for the parameter at all.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.