[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Michael Rans
Michael Rans added the comment: Thanks for all your help and advice. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Steven D'Aprano
Steven D'Aprano added the comment: > Another case is in round trip processing of JSON or YML. Sorry for my ignorance, but I don't see how or why an unordered comparison would help you with round-tripping JSON or YAML. The order of key:value pairs in JSON is not guaranteed to be preserved,

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Terry J. Reedy
Terry J. Reedy added the comment: -1 also for the reasons given. Michael, a question asking how would have made a good python-list post. So I posted the answers in "How to include insertion order in dict equality" -- nosy: +terry.reedy resolution: -> rejected stage: -> resolved

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg401022 ___ Python tracker ___ ___ Python-bugs-list

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 The dict API is too important to be burdened with a mostly useless and rarely needed method. Besides we already have simple ways to do it, for example: assert list(d.items()) == list(e.items()) or: assert OrderedDict(d) == OrderedDict(e)

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 The dict API is to important to be burdened with a mostly useless and rarely needed method. Besides we already have simple ways to do it, for example: assert list(d.items()) == list(e.items()) or: assert OrderedDict(d) == OrderedDict(e)

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Michael Rans
Michael Rans added the comment: Thank you. Another case is in round trip processing of JSON or YML. Other cases are where you would prefer an OrderedDict over a dict. I think the method would help clarify things because it would make it obvious that it is for ordered comparisons while the

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For tests it can be more convenient to use list(d1.items()) == list(d2.items()) because it can produce better report on failure. You can add a simple helper function if you use it multiple times in tests. -- nosy: +serhiy.storchaka

[issue45093] Add method to compare dicts accounting for order

2021-09-02 Thread Michael Rans
Michael Rans added the comment: My use case is in testing. Currently I use an OrderedDict, but since dict introduced ordering in 3.7, I was considering switching. For my test, I need to check that the dictionary is the same both in content and order. I can indeed use your one liner, but

[issue45093] Add method to compare dicts accounting for order

2021-09-02 Thread Steven D'Aprano
Steven D'Aprano added the comment: What is your use-case for having dicts that differ only in order compare unequal? I can't think of any reason why I would want such a comparison, but if I did, it's a trivial one-liner: d1 == d2 and all(k1 == k2 for k1, k2 in zip(d1, d2)) --

[issue45093] Add method to compare dicts accounting for order

2021-09-02 Thread Michael Rans
Change by Michael Rans : -- type: -> behavior ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue45093] Add method to compare dicts accounting for order

2021-09-02 Thread Michael Rans
New submission from Michael Rans : I suggest adding a method that allows comparing dicts taking into account the order - an ordered compare (since == does not do that). (Also for my other issue (https://bugs.python.org/issue45092) where I suggested that set be ordered to reduce confusion,