4.9. index_realsorted()

natsort.index_realsorted(seq, key=None, reverse=False, alg=0)

Return the list of the indexes used to sort the input sequence in a locale-aware manner.

Sorts a sequence in a locale-aware manner, but returns a list of sorted the indexes and not the sorted list. This list of indexes can be used to sort multiple lists by the sorted order of the given sequence.

This is a wrapper around index_natsorted(seq, alg=ns.REAL).

The behavior of index_realsorted() in natsort version >= 4.0.0 was the default behavior of index_natsorted() for natsort version < 4.0.0.

  • seq (iterable) – The sequence to sort.
  • key (callable, optional) – A key used to determine how to sort each element of the sequence. It is not applied recursively. It should accept a single argument and return a single value.
  • reverse ({True, False}, optional) – Return the list in reversed sorted order. The default is False.
  • alg (ns enum, optional) – This option is used to control which algorithm natsort uses when sorting. For details into these options, please see the ns class documentation. The default is ns.REAL.

out – The ordered indexes of the sequence.

Return type:



Use index_realsorted just like the builtin sorted:

>>> a = ['num5.10', 'num-3', 'num5.3', 'num2']
>>> index_realsorted(a)
[1, 3, 0, 2]