> If it turns out that there's a dict implementation that's faster by not > preserving order, collections.UnorderedDict could be added. > There could also be specialized implementations that pre-size the dict (cf: > C++ unordered_map::reserve), etc., etc. > But these are all future things, which might not be necessary.
I think that the problem with this is that for the most part, people will use `dict`, and for most uses of `dict`, order doesn't matter (and it never has before). Given that "arbitrary order" includes *any* fixed ordering (insertion ordered, reverse insertion ordered, etc), the common case should keep the existing "no order guarantee" specification. This gives interpreter authors maximum freedom with a fundamental, widely used data type. > Isn't ordered dict also useful for **kwargs? If this is useful (and it seems like it would be), I think again a syntax modification that allows users to indicate that they want a particular implementation of **kwargs would be better than modifying dict semantics. It could possibly be handled with a type-hinting like syntax: def f(*args, **kwargs : OrderedKwargs): Or a riff on the existing syntax: def f(*args, ***kwargs): def f(*args, ^^kwargs): def f(*args, .**kwargs): In this case, the only guarantee you'd need (which relatively minor compared to a change in the dict semantics) would be that keyword argument order passed to a function would be preserved as the order that it is passed into the `kwargs` constructor. The old **kwargs syntax would give you a `dict` as normal, and the new ^^kwargs would give you an OrderedDict or some other dict subclass with guaranteed order. On 11/05/2017 03:50 PM, Peter Ludemann via Python-Dev wrote: > > > On 5 November 2017 at 12:44, Sven R. Kunze <srku...@mail.de> wrote: > >> +1 from me too. >> >> On 04.11.2017 21:55, Jim Baker wrote: >> >> +1, as Guido correctly recalls, this language guarantee will work well >> with Jython when we get to the point of implementing 3.7+. >> >> On Sat, Nov 4, 2017 at 12:35 PM, Guido van Rossum <gu...@python.org> >> wrote: >> >>> This sounds reasonable -- I think when we introduced this in 3.6 we were >>> worried that other implementations (e.g. Jython) would have a problem with >>> this, but AFAIK they've reported back that they can do this just fine. So >>> let's just document this as a language guarantee. >>> >>> On Sat, Nov 4, 2017 at 10:30 AM, Stefan Krah <ste...@bytereef.org> wrote: >>> >>>> >>>> Hello, >>>> >>>> would it be possible to guarantee that dict literals are ordered in v3.7? >>>> >>>> >>>> The issue is well-known and the workarounds are tedious, example: >>>> >>>> https://mail.python.org/pipermail/python-ideas/2015-Decembe >>>> r/037423.html >>>> >>>> >>>> If the feature is guaranteed now, people can rely on it around v3.9. >>>> >>>> >>>> >>>> Stefan Krah >>>> >>>> >>>> >>>> _______________________________________________ >>>> Python-Dev mailing list >>>> Python-Dev@python.org >>>> https://mail.python.org/mailman/listinfo/python-dev >>>> Unsubscribe: https://mail.python.org/mailma >>>> n/options/python-dev/guido%40python.org >>>> >>> >>> >>> >>> -- >>> --Guido van Rossum (python.org/~guido <http://python.org/%7Eguido>) >>> >>> _______________________________________________ >>> Python-Dev mailing list >>> Python-Dev@python.org >>> https://mail.python.org/mailman/listinfo/python-dev >>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/jbaker% >>> 40zyasoft.com >>> >>> >> >> >> _______________________________________________ >> Python-Dev mailing >> listPython-Dev@python.orghttps://mail.python.org/mailman/listinfo/python-dev >> >> Unsubscribe: >> https://mail.python.org/mailman/options/python-dev/srkunze%40mail.de >> >> >> >> _______________________________________________ >> Python-Dev mailing list >> Python-Dev@python.org >> https://mail.python.org/mailman/listinfo/python-dev >> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ >> pludemann%40google.com >> >> > > > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/paul%40ganssle.io >
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com