SHARE
TWEET

podmnojestva_rekursiya

nikbel Mar 18th, 2019 (edited) 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set = [1, 2, 3]
  2.  
  3.  
  4. def generate_subset(set, mask=(pow(2,len(set))-1)):
  5.     if mask > pow(2,len(set))-1:
  6.         return "False"
  7.     if mask < 0: return
  8.    
  9.     result = []
  10.     for i in range(len(set)):
  11.         if  pow(2,i) & mask != 0:
  12.             result.append(set[i])
  13.     generate_subset(set, mask-1)
  14.     print(result)
  15.    
  16. generate_subset(set)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top