nodes: 0, module; 1, function_definition; 2, function_name:reverse_shortlex; 3, parameters; 4, block; 5, identifier:end; 6, identifier:other; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, while_statement; 12, identifier:excludeend; 13, False; 14, comment:"""Yield all intersections of end with other in reverse shortlex order.
  
      >>> ['{:03b}'.format(s) for s in reverse_shortlex(0b111, [0b011, 0b101, 0b110])]
      ['111', '011', '101', '110', '001', '010', '100', '000']
  
      >>> ', '.join(''.join(sorted(s))
      ... for s in reverse_shortlex({'a', 'b', 'c', 'd'},
      ... [{'b', 'c', 'd'}, {'a', 'c', 'd'}, {'a', 'b', 'd'}, {'a', 'b', 'c'}]))
      'abcd, bcd, acd, abd, abc, cd, bd, bc, ad, ac, ab, d, c, b, a, '
  
      >>> assert list(reverse_shortlex({1, 2}, [{1}, {2}], excludeend=True)) == \
          [{1}, {2}, set()]
      """; 15, not_operator; 16, block; 17, assignment; 18, identifier:queue; 19, block; 20, identifier:excludeend; 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:end; 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:end; 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 reverse_shortlex(end, other, excludeend=False):
      """Yield all intersections of end with other in reverse shortlex order.
  
      >>> ['{:03b}'.format(s) for s in reverse_shortlex(0b111, [0b011, 0b101, 0b110])]
      ['111', '011', '101', '110', '001', '010', '100', '000']
  
      >>> ', '.join(''.join(sorted(s))
      ... for s in reverse_shortlex({'a', 'b', 'c', 'd'},
      ... [{'b', 'c', 'd'}, {'a', 'c', 'd'}, {'a', 'b', 'd'}, {'a', 'b', 'c'}]))
      'abcd, bcd, acd, abd, abc, cd, bd, bc, ad, ac, ab, d, c, b, a, '
  
      >>> assert list(reverse_shortlex({1, 2}, [{1}, {2}], excludeend=True)) == \
          [{1}, {2}, set()]
      """
      if not excludeend:
          yield end
  
      queue = collections.deque([(end, 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))