On Fri, 29 Apr 2022 at 07:44, Steven D'Aprano <st...@pearwood.info> wrote:
>
> Especially not when that solution is easily mistaken for something else:
>
>     d -= 1  # Are we subtracting 1, or deleting key 1?
>

IMO it would make more sense to spell it as subtraction of two similar types:

d -= {1} # supporting sets would be nice
d -= {1: ...}

If subtraction on dicts is ever supported, I doubt it would allow
subtracting one key from the dict - it would make much more sense to
subtract another dictionary.

But for the single elimination case, pop() is perfect for the job.

Oh, and since we're making evidence-free predictions about
performance, I'm going to put in my guesses too: "if key in mydict:
del mydict[key]" will be slower than pop(), and the try/except could
be about comparable, but could be slightly slower or faster. (If we
were placing bets, I'd bet on pop() being the fastest of the three
overall, but that's a weaker prediction.) Now we just need someone to
make the ultimate benchmark so we can find out :)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4R6NY4KLQ6JEHCR7MFNABCBDR7PE4M62/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to