In Python2 I could use
def subsets(mySet):
return reduce(lambda z, x: z + [y + [x] for y in z], mySet, [[]])
to find all subsets of mySet. Python 3 has removed reduce.
What would be an equally concise rewrite of this for Python3?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a list of several possible implementations of the power set (the set of all subsets) algorithm in Python. Some are recursive, some are iterative, some of them don’t use
reduce. Plenty of options to choose from!