How to Find Subsets in a Python
- 1). Import the "set" module to access set functions:
>>>from sets import Set - 2). Create two sets. The first set, "x," will represent a larger set of data. The second set, "y," will represent a smaller set that you can compare to x in order to determine if it is a subset of x. The set y is considered a subset of x if all elements in y are also in x:
>>>x = Set([1, 4, 5, 6, 4, 3, 5, 7, 8, 2, 3])
>>>y = Set([1, 2, 3]) - 3). Determine if y is a subset of x with the "issubset" function built into all Python sets:
>>>y.issubset(x)
True - 4). Change y, adding a new element that does does not exist in x. Then check again to see if y is a subset of x:
>>>y = Set([1, 2, 10])
>>>y.issubset(x)
False
Source...