0

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.

1
  • The ~, {, |, } characters and the del special character are the only characters that come after letters in the ASCII table. Commented Sep 27, 2014 at 5:47

1 Answer 1

1

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
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.