This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients methane, remi.lapeyre, rhettinger, selik, serhiy.storchaka
Date 2018-05-24.11:06:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAEfz+Ty0D0jG0c3sPe2P4DRyfN9sqHrfrujkVYi_0LtW7YZ25g@mail.gmail.com>
In-reply-to <1527159256.66.0.682650639539.issue33462@psf.upfronthosting.co.za>
Content
> Rémi Lapeyre <remi.lapeyre@henki.fr> added the comment:

> >> I think it's a reasonable expectation as a python user to be able to
do reversed(dict(a=1, b=20) since the order is know defined in the
specifications.

> > I agree about "reasonable expectation".  But I'm interested in is it
really useful in real world?

> I do agree it's certainly used than the conservation of order but it's
not useless either. For example, it could help to get the latest section
defined in a YAML or INI file once parsed.

For rare cases, OrderedDict can be used.

> >> It seems inconsistent to have an order on dict, views and not have
reversed work on them.

> > "Have an order" doesn't mean "reversible".  For example, single linked
list is ordered, but not reversible.

> > While CPython implementation can provide efficient __reverse__, adding
__reverse__ means **all** Python implementation is expected to provide it.
> > For example, some Python implementation may be able to implement dict
with hashmap + single linked list.  If __reverse__ is added, it's not
possible anymore.

> Indeed they would have to use a double-linked-list here.

Doubly linked list is memory inefficient than singly linked list.
And memory efficiency of builtin type is very important, than types in
library like OrderedDict.

> > "Preserve insertion order" is very useful for many people.  So it's
guaranteed.
> > Then how useful "reversible" in real world, for many people?

> While this is true, the same argument could be said about the dict views.
Many many people don't know about them but they are still an interesting
feature that has its place in the standard library.

It's different problem and out of scope of this discussion.

> It definitely won't be the most used feature in Python nor a killer
feature but it seemed important enough to be included in OrderedDict (
https://github.com/python/cpython/blob/master/Lib/collections/__init__.py#L63)
since 3.5 and a C implementation of OrderedDict has been added in the same
release so it seems to have mattered at the time.

OrderedDict is more about "preserving insertion order".  It provides O(1)
`popitem(last=False)` and `move_to_end(last=False)`.
So "Reversible is essential for OrderedDict" is not enough reason for
"Reversible is essential for dict".

> Having this feature in the built-in dicts could actually help to simplify
the implementation of the collections module in this case.

Would you elaborate more?
History
Date User Action Args
2018-05-24 11:06:28methanesetrecipients: + methane, rhettinger, serhiy.storchaka, selik, remi.lapeyre
2018-05-24 11:06:28methanelinkissue33462 messages
2018-05-24 11:06:28methanecreate