nodes: 0, module; 1, function_definition; 2, function_name:patience_sort; 3, parameters; 4, block; 5, identifier:xs; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, string:'''Patience sort an iterable, xs.
  
      This function generates a series of pairs (x, pile), where "pile"
      is the 0-based index of the pile "x" should be placed on top of.
      Elements of "xs" must be less-than comparable.
      '''; 10, assignment; 11, identifier:x; 12, identifier:xs; 13, block; 14, identifier:pile_tops; 15, call; 16, expression_statement; 17, if_statement; 18, expression_statement; 19, identifier:list; 20, argument_list; 21, assignment; 22, comparison_operator:pile == len(pile_tops); 23, block; 24, else_clause; 25, yield; 26, identifier:pile; 27, call; 28, identifier:pile; 29, call; 30, expression_statement; 31, block; 32, expression_list; 33, attribute; 34, argument_list; 35, identifier:len; 36, argument_list; 37, call; 38, expression_statement; 39, identifier:x; 40, identifier:pile; 41, identifier:bisect; 42, identifier:bisect_left; 43, identifier:pile_tops; 44, identifier:x; 45, identifier:pile_tops; 46, attribute; 47, argument_list; 48, assignment; 49, identifier:pile_tops; 50, identifier:append; 51, identifier:x; 52, subscript; 53, identifier:x; 54, identifier:pile_tops; 55, identifier:pile
code: def patience_sort(xs):
      '''Patience sort an iterable, xs.
  
      This function generates a series of pairs (x, pile), where "pile"
      is the 0-based index of the pile "x" should be placed on top of.
      Elements of "xs" must be less-than comparable.
      '''
      pile_tops = list()
      for x in xs:
          pile = bisect.bisect_left(pile_tops, x)
          if pile == len(pile_tops):
              pile_tops.append(x)
          else:
              pile_tops[pile] = x
          yield x, pile