nodes: 0, module; 1, function_definition; 2, function_name:build_sort; 3, parameters; 4, block; 5, expression_statement; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, return_statement; 10, string; 11, assignment; 12, assignment; 13, assignment; 14, list_comprehension; 15, string_content:Build sort query paramter from kwargs; 16, identifier:sorts; 17, call; 18, identifier:sorts; 19, conditional_expression:[sorts] if isinstance(sorts, basestring) else sorts; 20, identifier:sorts; 21, list_comprehension; 22, dictionary; 23, for_in_clause; 24, if_clause; 25, attribute; 26, argument_list; 27, list; 28, call; 29, identifier:sorts; 30, call; 31, for_in_clause; 32, pair; 33, pattern_list; 34, identifier:sorts; 35, comparison_operator:s in SORTS; 36, attribute; 37, identifier:getlist; 38, string; 39, identifier:sorts; 40, identifier:isinstance; 41, argument_list; 42, attribute; 43, argument_list; 44, identifier:s; 45, identifier:sorts; 46, subscript; 47, identifier:d; 48, identifier:s; 49, identifier:d; 50, identifier:s; 51, identifier:SORTS; 52, identifier:request; 53, identifier:args; 54, string_content:sort; 55, identifier:sorts; 56, identifier:basestring; 57, identifier:s; 58, identifier:split; 59, string; 60, identifier:SORTS; 61, identifier:s; 62, string_content:
code: def build_sort():
      '''Build sort query paramter from kwargs'''
      sorts = request.args.getlist('sort')
      sorts = [sorts] if isinstance(sorts, basestring) else sorts
      sorts = [s.split(' ') for s in sorts]
      return [{SORTS[s]: d} for s, d in sorts if s in SORTS]