title: How to sort a list of different types?
body: <p>I need to sort a list using python 3. There might be <code>strings</code>, <code>integers</code>, <code>floats</code>, or <code>tuples</code>, etc. </p>
  
  <p>I am currently trying to make correct use of the <code>sort</code> function using the <code>key</code> parameter like this:</p>
  
  <pre><code>data.sort(key=gen_key)
  
  ...
  
  def gen_key(self, value):
          if is_number(value):
              return str(value)
  
          if isinstance(value, str):
              return value
      return '___' + type(value).__name__
  </code></pre>
  
  <p>But the problem is that numbers will now be sorted naturally. While I want to order the numbers and floats still like numbers and floats instead of treating them as strings.</p>
  
  <p>The behavior is caused by the <code>return str(value)</code> part. But i cannot return a different type than a string, as that will raise an exception, as of python 3 strings wont be sorted with numbers like they did in python 2. The exception is the following</p>
  
  <pre><code>unordarable types: int() &lt; str()
  </code></pre>
  
  <p>Any suggestions?</p>