Anonymous user
Sort using a custom comparator: Difference between revisions
→[[Python]]
Line 64:
==[[Python]]==
[[Category:Python]]
'''Interpreter''': 2.
<pre>
d = len(s2) - len(s1)
▲ strings = ["Here", "are", "some", "sample", "strings", "to", "be", "sorted"]
▲ strings.sort(mycmp)
# Alternative with decoration, unfit for very long lists:
print sorted(strings, key=lambda s: (-len(s), s))
</pre>
|