您好,我正在尝试对播放器类对象进行排序,其名称存储为属性,如下所示
class Player:
def __init__(self,license_no):
self.license = license_no
self.name = input('Oyuncunun adını ve soyadını giriniz: ').replace('ı','I').replace('i','İ').upper()
self.fide_rating = get_ratings('Oyuncunun FIDE kuvvet puanını giriniz: ')
self.national_rating = get_ratings('Oyuncunun ulusal kuvvet puanını giriniz: ')
self.points = 0
我在一个列表中有这些对象,我想按它们的名称属性对列表进行排序。我可以和接线员一起做。加上英文字母顺序很好,但我需要按土耳其语字母进行排序,土耳其语字母有“Ç”、“Ö”等字符。我如何做到这一点?感谢您的帮助
我相信我已经用这个名为PyICU的库解决了这个问题,这个库在这里使用:How do I sort unicode strings alphabetically in Python?
你想做这样的事吗
输出:
另一种方法是使用
str.translate
方法,该方法在两组字符串之间构建转换表,如下所示:然后,您可以在
Player
类中添加另一个属性,并调用它,例如self.translated_name
,在该类中,您使用该属性与operator.attrgetter
一起保存翻译名称和sort
:相关问题 更多 >
编程相关推荐