in reply to Re^2: Sort undef
in thread Sort undef
And, oh by the way, Perl did it in exactly the same way that every other language with a built-in SORT verb did.Actually, the sort function in Python 3 doesn't take a (two-arg) comparison function. It takes a (one-arg) key-generating function. Essentially, the Schwartzian transformation is built right in.
(You can play games with operator overloading to get comparison-function behavior, but that's considered "unpythonic.")>>> x = ['c','B','a'] >>> x.sort(); print(x) ['B', 'a', 'c'] >>> x.sort(key=str.lower); print(x) ['a', 'B', 'c']
|
---|