[issue39178] Should we make dict not accept a sequence of sets?

Steven D'Aprano report at bugs.python.org
Wed Jan 1 10:44:30 EST 2020


Steven D'Aprano <steve+python at pearwood.info> added the comment:

"should dict preemptively make sure it doesn't accept a sequence of sets"

No. The person on StackOverflow made a mistake in their code: they used an unordered data structure (set) instead of an ordered data structure (tuple):

    dict({i,j} for i,j in enumerate(lst))

It is a waste of time to slow down the dict constructor to check for something so unusual as this. Everyone will pay the cost of the checks and virtually no-one will get any benefit.

I'm closing this as "rejected", but if anyone disagrees they can reopen it.

By the way, the best way to initialise a dictionary in this situation is to avoid the unnecessary generator expression and just go straight to enumerate:

    dict(enumerate(lst))

----------
nosy: +steven.daprano
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39178>
_______________________________________


More information about the Python-bugs-list mailing list