nodes: 0, module; 1, function_definition; 2, function_name:_tupleCompare; 3, parameters; 4, block; 5, identifier:tuple1; 6, identifier:ineq; 7, identifier:tuple2; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, return_statement; 15, identifier:eq; 16, lambda; 17, identifier:ander; 18, identifier:AND; 19, identifier:orer; 20, identifier:OR; 21, comment:"""
      Compare two 'in-database tuples'.  Useful when sorting by a compound key
      and slicing into the middle of that query.
      """; 22, assignment; 23, identifier:limit; 24, call; 25, block; 26, call; 27, lambda_parameters; 28, parenthesized_expression; 29, identifier:orholder; 30, list; 31, identifier:range; 32, argument_list; 33, expression_statement; 34, expression_statement; 35, expression_statement; 36, identifier:orer; 37, argument_list; 38, identifier:a; 39, identifier:b; 40, comparison_operator:a==b; 41, call; 42, assignment; 43, assignment; 44, call; 45, list_splat; 46, identifier:a; 47, identifier:b; 48, identifier:len; 49, argument_list; 50, identifier:eqconstraint; 51, list_comprehension; 52, identifier:ineqconstraint; 53, call; 54, attribute; 55, argument_list; 56, identifier:orholder; 57, identifier:tuple1; 58, call; 59, for_in_clause; 60, identifier:ineq; 61, argument_list; 62, identifier:orholder; 63, identifier:append; 64, call; 65, identifier:eq; 66, argument_list; 67, pattern_list; 68, subscript; 69, subscript; 70, subscript; 71, identifier:ander; 72, argument_list; 73, identifier:elem1; 74, identifier:elem2; 75, identifier:elem1; 76, identifier:elem2; 77, call; 78, slice; 79, identifier:tuple1; 80, identifier:limit; 81, identifier:tuple2; 82, identifier:limit; 83, list_splat; 84, identifier:zip; 85, argument_list; 86, identifier:limit; 87, parenthesized_expression; 88, identifier:tuple1; 89, identifier:tuple2; 90, binary_operator:eqconstraint + [ineqconstraint]; 91, identifier:eqconstraint; 92, list; 93, identifier:ineqconstraint
code: def _tupleCompare(tuple1, ineq, tuple2,
                   eq=lambda a,b: (a==b),
                   ander=AND,
                   orer=OR):
      """
      Compare two 'in-database tuples'.  Useful when sorting by a compound key
      and slicing into the middle of that query.
      """
  
      orholder = []
      for limit in range(len(tuple1)):
          eqconstraint = [
              eq(elem1, elem2) for elem1, elem2 in zip(tuple1, tuple2)[:limit]]
          ineqconstraint = ineq(tuple1[limit], tuple2[limit])
          orholder.append(ander(*(eqconstraint + [ineqconstraint])))
      return orer(*orholder)