构建基于实习系统的动态排行机制
class Intern:
def __init__(self, name, score):
self.name = name
self.score = score
def __lt__(self, other):
return self.score > other.score
from queue import PriorityQueue
pq = PriorityQueue()
pq.put(Intern("Alice", 90))
pq.put(Intern("Bob", 85))
pq.put(Intern("Charlie", 95))
while not pq.empty():
intern = pq.get()
print(f"Intern: {intern.name}, Score: {intern.score}")
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!