Debian logoDebian Screenshots >


Natural sorting for Python (Python3)


natsort lets you apply natural sorting to your sequences easily, for example:

 >>> from natsort import natsorted
 >>> a = ['a2', 'a9', 'a1', 'a4', 'a10']
 >>> data = [['a1', 'a5'], ['a1', 'a40'], ['a10', 'a1'], ['a2', 'a5']]
 >>> natsorted(a)
 ['a1', 'a2', 'a4', 'a9', 'a10'
 >>> natsorted(data)
 [['a1', 'a5'], ['a1', 'a40'], ['a2', 'a5'], ['a10', 'a1']]

natsort identifies the numbers and sorts them separately from strings.

natsort comes with a shell script to use natural sorting in shell scripts. You can also execute natsort from the command line with python -m natsort.

There exists another natural sorting package for Python called python-naturalsort. You may prefer that package if you wish to only sort version numbers.

Upload more screenshots

Please help extend the collection of screenshots. Just make a screenshot and upload it here. You don't need to register or anything.



468 other people were interested in this package here. The newest known version of this software is 6.0.0-1 (Information last updated about 10 hours ago.)