Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

> casting c to a set will remove duplicates and allow faster iteration

Sorry, but this doesn't make any sense.  The *c* is either *self* or *other*, 
both of which are instances of Counter which is itself a subclass of dict.  So, 
the input cannot have duplicates keys.

> some minor benchmarks I ran seem to agree.

I'm dubious about the minor benchmarks.  If in fact the effect is real, it is 
merely exploiting an implementation quirk which is tenuous and subject to 
change (the premise would be that converting to a set and looping over a set is 
faster than the native dict iterator for a dict subclass).  Conceptually, it is 
always worse to spend the time and space for first converting to a set.

Besides a speed consideration, there is also a space consideration.  The 
existing code does not use any auxiliary memory.  The proposed code 
unnecessarily builds two new sets and then throws them away.

Thanks for the suggestion, but I am going to decline.  The timings seem 
dubious.  Conceptually, the PR makes the methods do more work.  To the extent 
some timing difference can be observed, it is likely an implementation quirk. 
The PR does not make the code cleaner or clearer, and it loops over a dict 
subclass in an unconventional way.  Also, the PR would have a negative impact 
on memory usage.

----------
nosy: +rhettinger

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46019>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to