nodes: 0, module; 1, function_definition; 2, function_name:shortlex; 3, parameters; 4, block; 5, identifier:start; 6, identifier:other; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, while_statement; 12, identifier:excludestart; 13, False; 14, comment:"""Yield all unions of start with other in shortlex order.
  
      >>> ['{:03b}'.format(s) for s in shortlex(0, [0b100, 0b010, 0b001])]
      ['000', '100', '010', '001', '110', '101', '011', '111']
  
      >>> ', '.join(''.join(sorted(s))
      ... for s in shortlex(set(), [{'a'}, {'b'}, {'c'}, {'d'}]))
      ', a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, abcd'
  
      >>> assert list(shortlex(set(), [{1}, {2}], excludestart=True)) == \
          [{1}, {2}, {1, 2}]
      """; 15, not_operator; 16, block; 17, assignment; 18, identifier:queue; 19, block; 20, identifier:excludestart; 21, expression_statement; 22, identifier:queue; 23, call; 24, expression_statement; 25, while_statement; 26, yield; 27, attribute; 28, argument_list; 29, assignment; 30, identifier:other; 31, block; 32, identifier:start; 33, identifier:collections; 34, identifier:deque; 35, list; 36, pattern_list; 37, call; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, if_statement; 42, tuple; 43, identifier:current; 44, identifier:other; 45, attribute; 46, argument_list; 47, assignment; 48, assignment; 49, yield; 50, identifier:other; 51, block; 52, identifier:start; 53, identifier:other; 54, identifier:queue; 55, identifier:popleft; 56, pattern_list; 57, expression_list; 58, identifier:result; 59, binary_operator:current | first; 60, identifier:result; 61, expression_statement; 62, identifier:first; 63, identifier:other; 64, subscript; 65, subscript; 66, identifier:current; 67, identifier:first; 68, call; 69, identifier:other; 70, integer:0; 71, identifier:other; 72, slice; 73, attribute; 74, argument_list; 75, integer:1; 76, identifier:queue; 77, identifier:append; 78, tuple; 79, identifier:result; 80, identifier:other
code: def shortlex(start, other, excludestart=False):
      """Yield all unions of start with other in shortlex order.
  
      >>> ['{:03b}'.format(s) for s in shortlex(0, [0b100, 0b010, 0b001])]
      ['000', '100', '010', '001', '110', '101', '011', '111']
  
      >>> ', '.join(''.join(sorted(s))
      ... for s in shortlex(set(), [{'a'}, {'b'}, {'c'}, {'d'}]))
      ', a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, abcd'
  
      >>> assert list(shortlex(set(), [{1}, {2}], excludestart=True)) == \
          [{1}, {2}, {1, 2}]
      """
      if not excludestart:
          yield start
  
      queue = collections.deque([(start, other)])
  
      while queue:
          current, other = queue.popleft()
  
          while other:
              first, other = other[0], other[1:]
              result = current | first
  
              yield result
  
              if other:
                  queue.append((result, other))