Skip to content
Advertisement

create a list of all the subsets of a given list in python 3.x

how can I create a list of all the subsets of a given list in python 3.x? the list given be like [1,2,3] and i want an output like

JavaScript

Advertisement

Answer

You can use itertools.combinations to get the combinations:

JavaScript

combining with list comprehension, you will get what you want:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement