在PythonPython的排序:子串
s= "ABCC"
n = len(s)
sorted(set([s[a:b] for a in range(n) for b in range(a+1,n+2)])
給我,按字母順序排序的子串用了重複
['A', 'AB', 'ABC', 'ABCC', 'B', 'BC', 'BCC', 'C', 'CC']
我怎樣才能進一步的子字符串的長度排序。
['A', 'B', 'C', 'AB', 'BC', 'CC', 'ABC', 'BCC', 'ABCC']
相關:http://stackoverflow.com/questions/14103620/length-wise-sorted-list-but-same-length-in-alphabetical-order-in -a-step –