On Thu, Sep 19, 2019 at 10:32 PM Steven D'Aprano <st...@pearwood.info> wrote:
>
> On Thu, Sep 19, 2019 at 03:26:27PM +1000, Chris Angelico wrote:
> > On Thu, Sep 19, 2019 at 3:08 PM Richard Higginbotham <higgi...@gmail.com> 
> > wrote:
> > >
> > > I'm not sure if there is any interest by others but I have frequently 
> > > come across cases where I would like to compare items in one list in 
> > > another similar to relational algebra. For example are the file names in 
> > > A in B and if so return a new list with those items. Long story short, I 
> > > wrote some functions to do that. They are quite simple and fast (due to 
> > > timsort in no small part). Even the plain python code is faster than the 
> > > built in set functions (afaik). I created a github and put the ones I 
> > > thought the community might like in there. 
> > > https://github.com/ponderpanda/listex
> > >
> > > an example would be
> > > a = [1,2,3,4,5,6]
> > > b = [1,3,7,4]
> > > list_intersection(a,b, sorta=True, sortb=True)
> > >
> > > returns [1,3,4]
> >
> > Can you elaborate on how this differs from using the built-in set type
> > for set operations? eg is this for situations where the values are not
> > all hashable?
>
> Sets are unordered and can contain no duplicates. Lists are ordered and
> can contain duplicates, so you might think of them as "ordered
> multisets".

With the sorta/sortb API and the algorithmic assumption that the heads
of both lists can be checked, I think the value of element order has
been lost, so the only significance is the possibility of duplicates.
The given use-case of file names doesn't justify this. So I'm curious
what the OP's actual use-case was for using lists here.

ChrisA
_______________________________________________
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/M5T6UKZMPWGDX4T37EFBRT2VJ3ETKGIM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to