3. natsort API¶
3.2. Convenience Functions¶
3.2.7. Help With Bytes On Python 3¶
The official stance of natsort
is to not support bytes for
sorting; there is just too much that can go wrong when trying to automate
conversion between bytes and str. But rather than completely give up
on bytes, natsort
provides three functions that make it easy to
quickly decode bytes to str so that sorting is possible.
3.2.8. Help With Creating Function Keys¶
If you need to create a complicated key argument to (for example)
natsorted()
that is actually multiple functions called one after the
other, the following function can help you easily perform this action. It is
used internally to natsort
, and has been exposed publicly for
the convenience of the user.
If you need to be able to search your input for numbers using the same
definition as natsort
, you can do so using the following function.
Given your chosen algorithm (selected using the ns
enum),
the corresponding regular expression to locate numbers will be returned.