[Python-ideas] Add dict.append and dict.extend

Chris Barker - NOAA Federal chris.barker at noaa.gov
Mon Jun 4 21:06:59 EDT 2018


> d.setdefault(key, value)

I though the OP wanted an error if the key already existed.

This is close, as it won’t change the dict if the key is already
there, but it will add it if it’s not.

@OP

Maybe post those five lines so we know exactly what you want — maybe
there is already a good solution. I know I spent years thinking “there
should be an easy way to do this” before I found setdefault().

-CHB

>
> :-)
>
> [snip]
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list