[issue45338] Add key argument to collections.Counter

2021-10-01 Thread kubat aytekin
New submission from kubat aytekin : Counter has become the default tool for counting occurences of objects in an iterable. However by construction it only works on hashable objects as it is a subclass of dict. Would it be possible to implement a "key=" keyword argument as i

[issue45338] Add key argument to collections.Counter

2021-10-01 Thread kubat aytekin
kubat aytekin added the comment: I was thinking about use cases where one might want to preserve the original key. I was not however aware of PEP 455 and the reasons for it's rejection. My bad. Yet It is still unclear to me what the best practice would be to reverse lookup unhas

[issue45338] Add key argument to collections.Counter

2021-10-01 Thread kubat aytekin
kubat aytekin added the comment: Or keep the reverse mapping in another dict: count = Counter() reverse_mapping = dict() for x in all_the_items: count.update(keyfunc(x)) reverse_mapping[keyfunc(x)] = x Anyways I'm closing it as it is a partial duplicate o