Feb-25-2019, 04:14 PM
As Larz said, this functionality is all covered in Python. But if you need to recreate it for homework, to get the subsets, start with a list of the empty set. Loop through the items in the set, adding to the list of subsets every subset plus the item:
>>> subsets = [[]] >>> fullset = [1, 2, 3] >>> for item in fullset: ... subsets = subsets + [subset + [item] for subset in subsets] ... >>> subsets [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]You should be able to modify that to get the list of subsets you want.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures