Path to this page:
./
textproc/py-natsort,
Natural sorting for python
Branch: pkgsrc-2020Q1,
Version: 6.2.0,
Package name: py37-natsort-6.2.0,
Maintainer: kamelderouicheWhen 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.
Required to run:[
devel/py-setuptools] [
lang/python37]
Required to build:[
pkgtools/cwrappers]
Master sites:
SHA1: 57d97a62c0177e9a14fb08979d048a6fdc095700
RMD160: f05e4956317c8d0e7d2ad8cf44ffc64acb251195
Filesize: 136.075 KB
Version history: (Expand)
- (2020-04-20) Package added to pkgsrc.se, version py37-natsort-6.2.0 (created)