parameters: (states)
return_statement: return statelist
docstring: For each item of states return a list containing all combinations of
      that item with individual bits reset, sorted by the number of set bits.
docstring_summary: For each item of states return a list containing all combinations of
      that item with individual bits reset, sorted by the number of set bits.
docstring_tokens: For each item of states return a list containing all combinations of that item with individual bits reset sorted by the number of set bits .
function: def expand_substates(states):
      '''For each item of states return a list containing all combinations of
      that item with individual bits reset, sorted by the number of set bits.
      '''
      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
function_tokens: 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