Reputation: 1209
What is the sorting order of characters in Python (or numpy)? is there any table?
[In] : np.sort(["a","c","b","-"])
[Out]: array(['-', 'a', 'b', 'c'],
dtype='|S1')
[In] : np.sort(["a","c","b","78"])
[Out]: array(['78', 'a', 'b', 'c'],
dtype='|S1')
Is there anything which would sort after the letters? Or, alternately, how is this order decided? I tried a lot of special characters, they all sort in the front.
sorted()
behaves the same way.
Upvotes: 0
Views: 656
Reputation: 9049
The builtin ord()
returns the value of an 8-bit character.
Try ord('a')
etc.
In [1]: ord('a')
Out[1]: 97
In [2]: ord('&')
Out[2]: 38
chr(97)
is the inverse of ord('a')
In [3]: table = {i: chr(i) for i in xrange(i)}
In [4]: table
...
Upvotes: 1