Hacker News new | past | comments | ask | show | jobs | submit login

One particular annoyance of OrderedDict objects was initialising them with literals. You couldn't just do:

    od = OrderedDict({
        "y": "first",
        "x": "second",
    })
because, by the time the data got to OrderedDict's constructor, it had already been through a dict. Instead you had to supply a list of lists (or tuple of tuples etc.):

    od = OrderedDict([
        ("y", "first"),
        ("x", "second"),
    ])
For hierarchically nested dictionaries, these are quite a bit harder to read.



But you can also just create them with named arguments, like this:

    collections.OrderedDict(y = "first", x = "second")


This also wasn't guaranteed to work since kwargs is a dict under the hood.


FWIW they could have used a special-purpose dict guaranteeing order for that. I don't know if they ended up using the normal dicts but the proposal to keep kwarg ordering predates the new dicts, and the PEP even notes that it's unclear the new dicts would be merged.

Same with class attribute ordering, PEP 520 still talks about using OrderedDict, however it was only merged after the new dicts, and even if ordering was not defined at the time (as part of Python-the-language) PEP 520 could use this internal property just fine and the ordereddict-based version was stripped out, the PEP was essentially accepted as a no-op (the ordering properties would just be officially documented).


kwarg order wasn't guaranteed either until Python 3.6.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: