def expand_substates(states):
 def nbits(n):
  'number of bits set in n base 2'
  nb = 0
  while n:
   (n, rem) = divmod(n, 2)
   nb += rem
  return nb
 statelist = []
 for state in states:
  substates = list(set(((state & x) for x in states)))
  substates.sort(key=nbits, reverse=True)
  statelist.append(substates)
 return statelist

def expand_substates ( states ) : def nbits ( n ) : nb = 0 while n : ( n , rem ) = divmod ( n , 2 ) nb += rem return nb statelist = [ ] for state in states : substates = list ( set ( ( ( state & x ) for x in states ) ) ) substates . sort ( key = nbits , reverse = True ) statelist . append ( substates ) return statelist
for each item of states return a list containing all combinations of that item with individual bits reset .