Advertisement
dbwonders

ps6_subsets

Jun 10th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def generate_all_subsets(hand_string):
  2.     """
  3.    Returns a sequence containing all the substrings of the string hand.  
  4.  
  5.    hand_string: string
  6.    """
  7.  
  8.     if len(hand_string) == 0:
  9.         return [""]        
  10.     subsets = generate_all_subsets(hand_string[1:])
  11.     ans = subsets[:]  
  12.     for subset in subsets:
  13.         ans.append(hand_string[0] + subset)
  14.     return ans  # list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement