From 3d62532a8f6fe74eba82e56896f7407cff293153 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Wed, 9 Jan 2019 11:50:54 -0500 Subject: [PATCH] More on sorting. Fix #33 --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87adfb7..8f4e1df 100644 --- a/README.md +++ b/README.md @@ -1808,13 +1808,37 @@ x.reverse() ```python +# Lexical sort by string value +# e.g. [1, 10, 2] x.sort(key = lambda item: str(item)) ``` ```coffeescript -x.sort() # sort by string value +# Lexical sort by string value +# e.g. [1, 10, 2] +x.sort() +``` + + + + +```python +# Sort by numeric value +# e.g. [1, 2, 10] +x.sort(key = lambda item: float(item)) +``` + + + +```coffeescript +# Sort by numeric value +# e.g. [1, 2, 10] +x.sort (x,y) -> x-y +# or, especially for stable sort: +_ = require 'underscore' #or lodash +x = _.sortBy x ```