On Sep 20, 2019, at 02:41, Richard Musil <risa20...@gmail.com> wrote:
> 
> I just added another implementation to the test (which I believe you had on 
> mind):
> ```
> def relcomp_set_list(a, b):
>     bset = set(b)
>     return [ia for ia in a if ia not in bset]

Or just `set(b).intersection(a)` and maybe checking the len to pick which one.

If you really want to go overboard with micro-optimizing this version, you 
might want to also check whether stashing bset.__contains__ and using that 
speeds things up (which may be different across recent versions of Python with 
changes to method calling?), and using it in filter instead of a comprehension 
(to move the loop fully into C, at the cost of needing to build a list out of 
an iterator at the end).

But I don’t really think we need to go overboard with that. We already know 
that using a set is faster except possibly when you already have pre-sorted 
lists, and if you do have that case, I’m not sure pressing further with this 
artificial benchmark will tell you much anyway.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CDIZ6VO5W57RCAZVGAD5P4FKWPODXRGA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to