2014-09-27 27 views
0

Python(或numpy)中字符的排序順序是什麼?有沒有桌子?Python(numpy)排序字符順序?

[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') 

有沒有什麼會在字母后面排序?或者,或者,這個訂單如何決定? 我嘗試了很多特殊字符,它們都排在前面。

sorted() 

表現相同的方式。

+0

逆的'〜','{','|','}'字符和'del'特殊字符是在[ASCII表](http://www.asciitable.com/)中的字母后面的唯一字符。 – SethMMorton 2014-09-27 05:47:15

回答

1

內建的ord()返回一個8位字符的值。

ord('a')嘗試等

In [1]: ord('a') 
Out[1]: 97 

In [2]: ord('&') 
Out[2]: 38 

chr(97)ord('a')

In [3]: table = {i: chr(i) for i in xrange(i)} 

In [4]: table 
...