包含utf-8字符的列表的排序 [英] sorting of list containing utf-8 characters
问题描述
问题的开头在这里自定义排序python
我想按此字母进行特殊排序
I want to make special sorting by this alphabet
alphabet = u'aáàAâÂbBcCçÇdDeéEfFgGğĞhHiİîÎíīıIjJkKlLmMnNóoOöÖpPqQrRsSşŞtTuUûúÛüÜvVwWxXyYzZ
[aáàAâ€] 这组字符应具有相同的优先级.在较早的线程中,@ happydave建议使用(alphabet.index(c)/2),
[aáàAâÂ] this group of characters should have same priority. In earlier thread, @happydave suggested to use (alphabet.index(c)/2),
应将列表中的每对相邻字符映射到 相同的优先级.
which should map each pair of adjacent characters in your list to the same priority.
但就我而言,我没有一对角色?例如:aáàAâÂ,eéE,uUûúÛ,óoO,iİîííī.
But in my case I don't have pair of character? for example: aáàAâÂ, eéE, uUûúÛ, óoO, iİîÎíī.
在我看来,简单的方法是在每个列表中添加一个仅包含成对字符的项目,但是我不知道如何实现.
In my opinion simple way is to add one item,containing only paired charachers to each list, but I don't know how to implement it.
[['word1', <Element tag at b719a4cc>], ['word2', <Element tag at b719a6cc>]]
添加了一项的列表清单
[['word1_', 'word1', <Element tag at b719a4cc>], ['word2_', 'word2', <Element tag at b719a6cc>]]
推荐答案
s='aáàAâÂbBcCçÇdDeéEfFgGğĞhHiİîÎíīıIjJkKlLmMnNóoOöÖpPqQrRsSşŞtTuUûúÛüÜvVwWxXyYzZ'
s2='aaaaaabbccccddeeeffgggghhiiiiiiiijjkkllmmnnoooooppqqrrssssttuuuuuuuvvwwxxyyzz'
trans = str.maketrans(s, s2)
def unikey(seq):
return seq[0].translate(trans)
将此函数用作sorted
这篇关于包含utf-8字符的列表的排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!