Feb-25-2019, 04:23 PM
(This post was last modified: Feb-25-2019, 04:23 PM by Hassediagram.)
(Feb-25-2019, 04:14 PM)ichabod801 Wrote: 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.
Thank you ichabod801, this works ! I will use your trick.
But why didn't it work in my program ?
Thank you also for your suggestion about the intersections.