nodes: 0, module; 1, function_definition; 2, function_name:sort_by_list_order; 3, parameters; 4, block; 5, identifier:sortlist; 6, identifier:reflist; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, function_definition; 12, if_statement; 13, return_statement; 14, identifier:reverse; 15, False; 16, identifier:fltr; 17, False; 18, identifier:slemap; 19, None; 20, comment:"""
      Sort a list according to the order of entries in a reference list.
  
      Parameters
      ----------
      sortlist : list
        List to be sorted
      reflist : list
        Reference list defining sorting order
      reverse : bool, optional (default False)
        Flag indicating whether to sort in reverse order
      fltr : bool, optional (default False)
        Flag indicating whether to filter `sortlist` to remove any entries
        that are not in `reflist`
      slemap : function or None, optional (default None)
         Function mapping a sortlist entry to the form of an entry in
         `reflist`
  
      Returns
      -------
      sortedlist : list
        Sorted (and possibly filtered) version of sortlist
      """; 21, function_name:keyfunc; 22, parameters; 23, block; 24, identifier:fltr; 25, block; 26, call; 27, identifier:entry; 28, if_statement; 29, if_statement; 30, if_statement; 31, identifier:sorted; 32, argument_list; 33, comparison_operator:slemap is not None; 34, block; 35, comparison_operator:rle in reflist; 36, comment:# Ordering index taken from reflist; 37, block; 38, else_clause; 39, identifier:slemap; 40, block; 41, else_clause; 42, identifier:sortlist; 43, keyword_argument; 44, keyword_argument; 45, identifier:slemap; 46, None; 47, expression_statement; 48, identifier:rle; 49, identifier:reflist; 50, return_statement; 51, comment:# Ordering index taken from sortlist, offset; 52, comment:# by the length of reflist so that entries; 53, comment:# that are not in reflist retain their order; 54, comment:# in sortlist; 55, block; 56, expression_statement; 57, block; 58, identifier:key; 59, identifier:keyfunc; 60, identifier:reverse; 61, identifier:reverse; 62, assignment; 63, call; 64, return_statement; 65, assignment; 66, expression_statement; 67, identifier:rle; 68, call; 69, attribute; 70, argument_list; 71, binary_operator:sortlist.index(entry) + len(reflist); 72, identifier:sortlist; 73, call; 74, assignment; 75, identifier:slemap; 76, argument_list; 77, identifier:reflist; 78, identifier:index; 79, identifier:rle; 80, call; 81, call; 82, identifier:filter; 83, argument_list; 84, identifier:sortlist; 85, call; 86, identifier:entry; 87, attribute; 88, argument_list; 89, identifier:len; 90, argument_list; 91, lambda; 92, identifier:sortlist; 93, identifier:filter; 94, argument_list; 95, identifier:sortlist; 96, identifier:index; 97, identifier:entry; 98, identifier:reflist; 99, lambda_parameters; 100, comparison_operator:slemap(x) in reflist; 101, lambda; 102, identifier:sortlist; 103, identifier:x; 104, call; 105, identifier:reflist; 106, lambda_parameters; 107, comparison_operator:x in reflist; 108, identifier:slemap; 109, argument_list; 110, identifier:x; 111, identifier:x; 112, identifier:reflist; 113, identifier:x
code: def sort_by_list_order(sortlist, reflist, reverse=False, fltr=False,
                         slemap=None):
      """
      Sort a list according to the order of entries in a reference list.
  
      Parameters
      ----------
      sortlist : list
        List to be sorted
      reflist : list
        Reference list defining sorting order
      reverse : bool, optional (default False)
        Flag indicating whether to sort in reverse order
      fltr : bool, optional (default False)
        Flag indicating whether to filter `sortlist` to remove any entries
        that are not in `reflist`
      slemap : function or None, optional (default None)
         Function mapping a sortlist entry to the form of an entry in
         `reflist`
  
      Returns
      -------
      sortedlist : list
        Sorted (and possibly filtered) version of sortlist
      """
  
      def keyfunc(entry):
          if slemap is not None:
              rle = slemap(entry)
          if rle in reflist:
              # Ordering index taken from reflist
              return reflist.index(rle)
          else:
              # Ordering index taken from sortlist, offset
              # by the length of reflist so that entries
              # that are not in reflist retain their order
              # in sortlist
              return sortlist.index(entry) + len(reflist)
  
      if fltr:
          if slemap:
              sortlist = filter(lambda x: slemap(x) in reflist, sortlist)
          else:
              sortlist = filter(lambda x: x in reflist, sortlist)
  
      return sorted(sortlist, key=keyfunc, reverse=reverse)