Message359161
"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)) |
|
Date |
User |
Action |
Args |
2020-01-01 15:44:30 | steven.daprano | set | recipients:
+ steven.daprano, rhettinger, methane, serhiy.storchaka, DeepSpace |
2020-01-01 15:44:30 | steven.daprano | set | messageid: <1577893470.17.0.568137170886.issue39178@roundup.psfhosted.org> |
2020-01-01 15:44:30 | steven.daprano | link | issue39178 messages |
2020-01-01 15:44:29 | steven.daprano | create | |
|