Actually, for dicts the implementation came first.
On Sun, Dec 15, 2019 at 19:50 Larry Hastings firstname.lastname@example.org wrote:
That's not a reason why we shouldn't do it. Python is the language where speed, correctness, and readability trump performance every time. We should decide what semantics we want, then do that, period. And anyway, it seems like some genius always figures out how to make it fast sooner or later ;-)
I can believe that, given the current implementation, sets might give up some of their optimizations if they maintained insertion order. But I don't understand what "flexibility" they would lose. Apart from being slower, what would set objects give up if they maintained insertion order? Are there operations on set objects that would no longer be possible?
On 12/15/19 6:58 PM, Tim Peters wrote:
As of 3.7, dict objects are guaranteed to maintain insertion order. But set objects make no such guarantee, and AFAIK in practice they don't maintain insertion order either.
If they ever appear to, it's an accident you shouldn't rely on.
From Raymond, 22 Dec 2017: https://twitter.com/raymondh/status/944454031870607360 """ Sets use a different algorithm that isn't as amendable to retaining insertion order. Set-to-set operations lose their flexibility and optimizations if order is required. Set mathematics are defined in terms of unordered sets. In short, set ordering isn't in the immediate future. """
Which is more an answer to "will they?" than "should they?" ;-)
Python-Dev mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://email@example.com/message/U72GJCRH... Code of Conduct: http://python.org/psf/codeofconduct/