nodes: 0, module; 1, function_definition; 2, function_name:unique; 3, parameters; 4, block; 5, identifier:s; 6, expression_statement; 7, expression_statement; 8, if_statement; 9, comment:# Try using a dict first, as that's the fastest and will usually; 10, comment:# work.  If it doesn't work, it will usually fail quickly, so it; 11, comment:# usually doesn't cost much to *try* it.  It requires that all the; 12, comment:# sequence elements be hashable, and support equality comparison.; 13, expression_statement; 14, try_statement; 15, delete_statement; 16, comment:# We can't hash all the elements.  Second fastest is to sort,; 17, comment:# which brings the equal elements together; then duplicates are; 18, comment:# easy to weed out in a single pass.; 19, comment:# NOTE:  Python's list.sort() was designed to be efficient in the; 20, comment:# presence of many duplicate elements.  This isn't true of all; 21, comment:# sort functions in all languages or libraries, so this approach; 22, comment:# is more effective in Python than it may be elsewhere.; 23, try_statement; 24, delete_statement; 25, comment:# Brute force is all that's left.; 26, expression_statement; 27, for_statement; 28, return_statement; 29, comment:"""Return a list of the elements in s, but without duplicates.
  
      For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3],
      unique("abcabc") some permutation of ["a", "b", "c"], and
      unique(([1, 2], [2, 3], [1, 2])) some permutation of
      [[2, 3], [1, 2]].
  
      For best speed, all sequence elements should be hashable.  Then
      unique() will usually work in linear time.
  
      If not possible, the sequence elements should enjoy a total
      ordering, and if list(s).sort() doesn't raise TypeError it's
      assumed that they do enjoy a total ordering.  Then unique() will
      usually work in O(N*log2(N)) time.
  
      If that's not possible either, the sequence elements must support
      equality-testing.  Then unique() will usually work in quadratic
      time.
      """; 30, assignment; 31, comparison_operator:n == 0; 32, block; 33, assignment; 34, block; 35, except_clause; 36, else_clause; 37, identifier:u; 38, block; 39, except_clause; 40, else_clause; 41, identifier:t; 42, assignment; 43, identifier:x; 44, identifier:s; 45, block; 46, identifier:u; 47, identifier:n; 48, call; 49, identifier:n; 50, integer:0; 51, return_statement; 52, identifier:u; 53, dictionary; 54, for_statement; 55, identifier:TypeError; 56, block; 57, block; 58, expression_statement; 59, identifier:TypeError; 60, block; 61, block; 62, identifier:u; 63, list; 64, if_statement; 65, identifier:len; 66, argument_list; 67, list; 68, identifier:x; 69, identifier:s; 70, block; 71, pass_statement; 72, comment:# move on to the next method; 73, return_statement; 74, assignment; 75, pass_statement; 76, comment:# move on to the next method; 77, assert_statement; 78, expression_statement; 79, expression_statement; 80, while_statement; 81, return_statement; 82, comparison_operator:x not in u; 83, block; 84, identifier:s; 85, expression_statement; 86, call; 87, identifier:t; 88, call; 89, comparison_operator:n > 0; 90, assignment; 91, assignment; 92, comparison_operator:i < n; 93, block; 94, subscript; 95, identifier:x; 96, identifier:u; 97, expression_statement; 98, assignment; 99, identifier:list; 100, argument_list; 101, identifier:sorted; 102, argument_list; 103, identifier:n; 104, integer:0; 105, identifier:last; 106, subscript; 107, identifier:lasti; 108, assignment; 109, identifier:i; 110, identifier:n; 111, if_statement; 112, expression_statement; 113, identifier:t; 114, slice; 115, call; 116, subscript; 117, integer:1; 118, call; 119, identifier:s; 120, identifier:t; 121, integer:0; 122, identifier:i; 123, integer:1; 124, comparison_operator:t[i] != last; 125, block; 126, assignment; 127, identifier:lasti; 128, attribute; 129, argument_list; 130, identifier:u; 131, identifier:x; 132, attribute; 133, argument_list; 134, subscript; 135, identifier:last; 136, expression_statement; 137, expression_statement; 138, identifier:i; 139, binary_operator:i + 1; 140, identifier:u; 141, identifier:append; 142, identifier:x; 143, identifier:u; 144, identifier:keys; 145, identifier:t; 146, identifier:i; 147, assignment; 148, assignment; 149, identifier:i; 150, integer:1; 151, subscript; 152, assignment; 153, identifier:lasti; 154, binary_operator:lasti + 1; 155, identifier:t; 156, identifier:lasti; 157, identifier:last; 158, subscript; 159, identifier:lasti; 160, integer:1; 161, identifier:t; 162, identifier:i
code: def unique(s):
      """Return a list of the elements in s, but without duplicates.
  
      For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3],
      unique("abcabc") some permutation of ["a", "b", "c"], and
      unique(([1, 2], [2, 3], [1, 2])) some permutation of
      [[2, 3], [1, 2]].
  
      For best speed, all sequence elements should be hashable.  Then
      unique() will usually work in linear time.
  
      If not possible, the sequence elements should enjoy a total
      ordering, and if list(s).sort() doesn't raise TypeError it's
      assumed that they do enjoy a total ordering.  Then unique() will
      usually work in O(N*log2(N)) time.
  
      If that's not possible either, the sequence elements must support
      equality-testing.  Then unique() will usually work in quadratic
      time.
      """
  
      n = len(s)
      if n == 0:
          return []
  
      # Try using a dict first, as that's the fastest and will usually
      # work.  If it doesn't work, it will usually fail quickly, so it
      # usually doesn't cost much to *try* it.  It requires that all the
      # sequence elements be hashable, and support equality comparison.
      u = {}
      try:
          for x in s:
              u[x] = 1
      except TypeError:
          pass    # move on to the next method
      else:
          return list(u.keys())
      del u
  
      # We can't hash all the elements.  Second fastest is to sort,
      # which brings the equal elements together; then duplicates are
      # easy to weed out in a single pass.
      # NOTE:  Python's list.sort() was designed to be efficient in the
      # presence of many duplicate elements.  This isn't true of all
      # sort functions in all languages or libraries, so this approach
      # is more effective in Python than it may be elsewhere.
      try:
          t = sorted(s)
      except TypeError:
          pass    # move on to the next method
      else:
          assert n > 0
          last = t[0]
          lasti = i = 1
          while i < n:
              if t[i] != last:
                  t[lasti] = last = t[i]
                  lasti = lasti + 1
              i = i + 1
          return t[:lasti]
      del t
  
      # Brute force is all that's left.
      u = []
      for x in s:
          if x not in u:
              u.append(x)
      return u