Python 3.0 - is this true?

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Sun Nov 9 18:10:15 CET 2008


Terry Reedy writes:
> If you want to duplicate 2.x behavior, which does *not* work for all
> types...
>
> def py2key(item): return (str(type(item)), item)

Nope.
  sorted((-1, 2, True, False))             == [-1, False, True, 2]
  sorted((-1, 2, True, False), key=py2key) == [False, True, -1, 2]
Might often be good enough though.  But uses more memory.

-- 
Hallvard



More information about the Python-list mailing list