Re: [Python-Dev] Real-world use of Counter

2014年11月06日 07:49:29 -0800

On Thu, Nov 6, 2014 at 1:10 AM, Nick Coghlan <[email protected]> wrote:
> Right. Especially in a ducktyping context, AttributeError and TypeError
> are often functionally equivalent - it usually isn't worthwhile adding code
> specifically to turn one into the other.
>
Yeah, these are so often interchangeable that I wish they had a common
ancestor. Then again when you are catching these you might as well be
catching all exceptions.
> The case that doesn't throw an exception at all seems a little strange,
> but I haven't looked into the details.
>
It comes from a simple approach to creating an intersection; paraphrasing,
the code does this:
def intesection(a, b):
 result = set()
 for x in a:
 if x in b:
 result.add(x)
 return result
If a is empty this never looks at b. I think it's okay not to raise in this
case (though it would also be okay if it *did* raise).
-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to