import collections from random import choice Card = collections.namedtuple('Card',['rank', 'suit']) class FrenchDeck: ranks = [str(n) for n in range(2,11)] + list('JQKA') suits = 'spades diamonds clubs hearts'.split() def __init__(self): self._cards = [Card(rank, suit) for suit in self.suits for rank in self.ranks] def __len__(self): return len(self._cards) def __getitem__(self, position): return self._cards[position] suit_values = dict(spades=3, hearts=2, diamonds=1, clubs=0) def spades_high(card): rank_value = FrenchDeck.ranks.index(card.rank) return rank_value * len(suit_values) + suit_values[card.suit] deck =FrenchDeck() for card in sorted(deck, keys=spades_high()): #doctest: +ElLIPSIS print(card) 代码如上 nameerror name spades high is not defined
悬赏问题
- ¥15 三分类机器学习模型可视化分析
- ¥15 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)
- ¥50 Qt在release捕获异常并跟踪堆栈(有Demo,跑一下环境再回答)
- ¥30 python,LLM 文本提炼
- ¥15 关于将inet引入的相关问题
- ¥15 关于一个倒计时的操作和显示设计
- ¥15 提问STK的问题,哪位航天领域的同学会啊
- ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
- ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
- ¥15 关于#java#的问题,请各位专家解答!