Python 最大字符串堆

CS_*_*_EE 8 python python-3.x

获得最大堆的建议方法是将键乘以 -1。拥有最大字符串堆的建议方法是什么?

是否有具有该功能的替代库?

me_*_*str 6

创建您自己的自定义字符串类:

class MyString:
    def __init__(self, word):
        self.word = word

    def __lt__(self, other):
        return self.word > other.word

    def __eq__(self, other):
        return self.word == other.word
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

heapq.heappush(heap, MyString(word))    
Run Code Online (Sandbox Code Playgroud)


Gre*_*Guy 0

通过将字符值设为负数来反转字符串?全小写字符串的键示例:

lambda s: ''.join(chr(ord('z') - ord(c) + ord('a')) for c in s)
Run Code Online (Sandbox Code Playgroud)