classification
Title: Add __le__ and __ge__ to collections.Counter
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Implement partial order on Counter
View: 22515
Assigned To: Nosy List: Wheerd, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-09-28 09:14 by Wheerd, last changed 2016-09-28 13:43 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
counter_comparison.patch Wheerd, 2016-09-28 09:14 A patch file with an implementation review
Messages (3)
msg277597 - (view) Author: Manuel Krebber (Wheerd) * Date: 2016-09-28 09:14
I would really like there to be comparison operators for collection.Counter similar to the ones for sets. While you can now use minus to some degree for that comparison, it is very inefficient. I have attached an implementation of __ge__ and __le__ as a patch. I could also provide the necessary additions to the documentation, if that is desired.
msg277598 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-28 09:18
This is a duplicate of issue22515.
msg277601 - (view) Author: Manuel Krebber (Wheerd) * Date: 2016-09-28 09:51
Oh, I should have searched properly before creating this ticket. Sorry about that. I guess I will be subclassing Counter in my project then, to get this functionality... Only problem is, that when using the builtin __add__ etc. of my Counter subclass, I will get a Counter instance, that does not support ordering... So I guess I will not use it at all.
History
Date User Action Args
2016-09-28 13:43:55r.david.murraysetstatus: open -> closed
2016-09-28 09:51:05Wheerdsetmessages: + msg277601
2016-09-28 09:18:28serhiy.storchakasetnosy: + rhettinger, serhiy.storchaka
messages: + msg277598
resolution: duplicate

superseder: Implement partial order on Counter
2016-09-28 09:14:43Wheerdcreate