[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Suggestion of new program: execute mathematical set operations on lists



Hi, a quick googling returns me this link [1]

seems that python natively do some sort of this

python3


>>> a = set([3, 3, 2, 5, 1])
>>> a
{1, 2, 3, 5}
>>> b = set([5, 90, 2, 7])
>>> b
{90, 2, 5, 7}
>>> a | b
{1, 2, 3, 5, 7, 90}
>>> a & b
{2, 5}
>>> 




[1] http://unix.stackexchange.com/questions/11343/linux-tools-to-treat-files-as-sets-and-perform-set-operations-on-them


cheers,

G.




Il Venerdì 25 Settembre 2015 18:11, Frank Stähr <der-storch-85@gmx.net> ha scritto:
Hello everybody,

I am not yet looking for a sponsor, but going to program a tiny tool:

"setop" takes as inputs several lists/sets, calculates desired 
(mathematical) set operations on them and outputs the final set (or 
depending on operation resulting number of elements, answer yes/no, …).

For example: File A contains 3 3 2 5 1 (each number an extra line). Then
setop A
would result in 1 2 3 5. This is equivalent to
sort | uniq

With a file B containing 5 90 2 7 the command
setop -i A B
would yield 2 5.

Here, -i stands for intersection. Of course, there is no limitation to 
numbers, elements can be any non-empty strings. Other operations are 
union, symmetric difference, difference, contains element, is subset, 
cardinality and so on.
Is this tool senseful, is there a certain need for it?

As you can see on 
<http://www.catonmat.net/blog/set-operations-in-unix-shell-simplified/> 
nearly all these operations can already be done with other tools, but 
the according command lines are mostly very tortuous. There doesn’t seem 
to be a tool that directly works with sets.

So my questions is: Is there a need for such a program or is there 
already something very similar? (Is this the right place for asking?)
I even exactly know what options setop should have and what it can do 
(how it is used), but am waiting for some responses from you before 
programming.

Note: I already asked two years ago but didn’t get satisfactory 
responses. Only now I remembered my idea.

I would be very grateful for your feedback,
Frank


Reply to: