Python sorting

From wikinotes
Revision as of 16:11, 6 February 2021 by Will (talk | contribs) (Created page with " <source lang="python"> foo = sorted(['z', 'b', 'a']) # new copy sort(mylist) # mutates 'mylist' sorted(mylist, key=lambda x: x % 2) # sort by result of 'k...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
foo = sorted(['z', 'b', 'a'])  # new copy
sort(mylist)                   # mutates 'mylist'
sorted(mylist, key=lambda x: x % 2)  # sort by result of 'key'