最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - RuleBasedCollator rule ignored - Stack Overflow

programmeradmin1浏览0评论

I'm trying to use the icu RuleBasedCollator in python. In my code I specify a rule wherby "ä" should sort before "a" as a secondary (accent) difference

from icu import RuleBasedCollator

l=["a","ä"]
rbc = RuleBasedCollator('\n&ä<<a')
sorted(l, key=rbc.getSortKey)

However, the output of the sorted is:

['a', 'ä']

I expected: ['ä','a'] What did I do wrong?

Many thanks

I'm trying to use the icu RuleBasedCollator in python. In my code I specify a rule wherby "ä" should sort before "a" as a secondary (accent) difference

from icu import RuleBasedCollator

l=["a","ä"]
rbc = RuleBasedCollator('\n&ä<<a')
sorted(l, key=rbc.getSortKey)

However, the output of the sorted is:

['a', 'ä']

I expected: ['ä','a'] What did I do wrong?

Many thanks

Share Improve this question asked 2 days ago korppu73korppu73 3392 gold badges3 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It appears that the difference between a and ä is considered primary. Using [before 1] you can achieve the expected result.

from icu import RuleBasedCollator

l=["a","ä"]
rbc = RuleBasedCollator('&[before 1]a < ä')
print(sorted(l, key=rbc.getSortKey))

To read more

发布评论

评论列表(0)

  1. 暂无评论