title: Fastest way to get sorted unique list in python?
body: <p>What is the fasted way to get a sorted, unique list in python? (I have a list of hashable things, and want to have something I can iterate over - doesn't matter whether the list is modified in place, or I get a new list, or an iterable. In my concrete use case, I'm doing this with a throwaway list, so in place would be more memory efficient.)</p>
  
  <p>I've seen solutions like</p>
  
  <pre><code>input = [5, 4, 2, 8, 4, 2, 1]
  sorted(set(input))
  </code></pre>
  
  <p>but it seems to me that first checking for uniqueness and then sorting is wasteful (since when you sort the list, you basically have to determine insertion points, and thus get the uniqueness test as a side effect). Maybe there is something more along the lines of unix's</p>
  
  <pre><code>cat list | sort | uniq
  </code></pre>
  
  <p>that just picks out consecutive duplications in an already sorted list?</p>
  
  <hr>
  
  <p>Note in the question ' <a href="https://stackoverflow.com/questions/2527405/fastest-way-to-uniqify-a-list-in-python">Fastest way to uniqify a list in Python</a>  ' the list is not sorted, and ' <a href="https://stackoverflow.com/questions/2931672/what-is-the-cleanest-way-to-do-a-sort-plus-uniq-on-a-python-list">What is the cleanest way to do a sort plus uniq on a Python list?</a> ' asks for the cleanest / most pythonic way, and the accepted answer suggests <code>sorted(set(input))</code>, which I'm trying to improve on.</p>