diff options
author | jdolecek <jdolecek> | 2016-11-30 14:13:48 +0000 |
---|---|---|
committer | jdolecek <jdolecek> | 2016-11-30 14:13:48 +0000 |
commit | c03114bd4d3c54264a3c7122ce9ef2265b7da796 (patch) | |
tree | 43e779ed25d8efbcba0faad6369b3dcf90b55414 /textproc/py-natsort/DESCR | |
parent | 389e2c0095c307502787e37a53d686165ea3632b (diff) | |
download | pkgsrc-c03114bd4d3c54264a3c7122ce9ef2265b7da796.tar.gz |
Add py-natsort 5.0.1 - Natural sorting for Python
based on wip version
Diffstat (limited to 'textproc/py-natsort/DESCR')
-rw-r--r-- | textproc/py-natsort/DESCR | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/textproc/py-natsort/DESCR b/textproc/py-natsort/DESCR new file mode 100644 index 00000000000..9eef59e1409 --- /dev/null +++ b/textproc/py-natsort/DESCR @@ -0,0 +1,25 @@ +When you try to sort a list of strings that contain numbers, the +normal python sort algorithm sorts lexicographically, so you might +not get the results that you expect: + +>>> a = ['a2', 'a9', 'a1', 'a4', 'a10'] +>>> sorted(a) +['a1', 'a10', 'a2', 'a4', 'a9'] + +Notice that it has the order (‘1’, ‘10’, ‘2’) - this is because the +list is being sorted in lexicographical order, which sorts numbers +like you would letters (i.e. ‘b’, ‘ba’, ‘c’). + +natsort provides a function natsorted that helps sort lists +“naturally”, either as real numbers (i.e. signed/unsigned floats +or ints), or as versions. Using natsorted is simple: + +>>> from natsort import natsorted +>>> a = ['a2', 'a9', 'a1', 'a4', 'a10'] +>>> natsorted(a) +['a1', 'a2', 'a4', 'a9', 'a10'] + +natsorted identifies numbers anywhere in a string and sorts them +naturally. Here are some other things you can do with natsort (please +see the examples for a quick start guide, or the api for more +details). |