Sorting kits (not one set)

I have many sets with each set representing unique elements in a single data file. Some of these sets are subsets of others; some are identical.

Is there a primitive or module that allows me to sort such sets that I get something like

A <= B <= C <= D <= E

et cetera for sets A, B, C, D, E, F?

those. sort not elements from the set, but sort by your relationships as subsets and supersets of each other?

+4
source share
1 answer

. , <= True, . , , , - .

:

>>> A = {1, 2}
>>> B = A | {3}
>>> C = B.copy()
>>> D = C | {4}
>>> A <= D
True
>>> [B, C, D, A]
[set([1, 2, 3]), set([1, 2, 3]), set([1, 2, 3, 4]), set([1, 2])]
>>> sorted([B, C, D, A])
[set([1, 2]), set([1, 2, 3]), set([1, 2, 3]), set([1, 2, 3, 4])]

: , False , . , , .

+8

All Articles