code: def _subsets_sorted(tupl):
      def helper(seq):
          if not seq:
              yield ()
          else:
              obj = seq[0]
              for subset in _subsets_sorted(seq[1:]):
                  yield subset
                  yield (obj,) + subset
  
      # Transform each obj -> (idx, obj) tuple, so that we can later sort them
      # by their position in the original list.
      expanded = list(enumerate(tupl))
      expanded_subsets = list(helper(expanded))
      # This exploits Python's stable sort: we want short before long, and ties
      # broken by natural ordering on the (idx, obj) entries in each subset. So
      # we sort by the latter first, then by the former.
      expanded_subsets.sort()
      expanded_subsets.sort(key=len)
      # And finally, we strip off the idx's:
      for subset in expanded_subsets:
          yield tuple([obj for (idx, obj) in subset])
  
imports: from __future__ import print_function
  from patsy.util import no_pickling
label_desc: Use image node_id 3 for calling a global function with example usage: _subsets_sorted(tupl) without return types