Python Forum

Full Version: why do we need dict.get() ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(May-12-2023, 08:05 AM)buran Wrote: [ -> ]It's doing exactly that, except that I don't understand what would be the purpose of the second argument of your dict.put() - i.e. it doesn't make sense to have 3 arguments for what you describe

the first argument would be the key. if the key is present, store argument 2 under that key. if the key is not present, add the key with argument 3 stored under it. i could even add a 4th argument as an additional test against the stored value under the found key (for argument 2). but i don't know if it should be a != test or an is not test.
Pages: 1 2