concepts.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:mau-mau 作者: obestwalter 项目源码 文件源码
def fetch(self, criterion=None):
        """Fetch one or several cards from the collection.

        * Given (None, 0, 1): fetch first card from the collection
        * Given a specific card: fetch that specific card
        * Given a number > 1: return a list of cards
        :rtype: Card or list of Card
        """
        if not self.cards:
            raise exceptions.NoCardsLeft()

        try:
            if not criterion or criterion == 1:
                return self.cards.pop(0)

            if isinstance(criterion, Integral):
                return [self.cards.pop(i) for i in range(criterion)]

            return self.cards.pop(self.cards.index(criterion))
        except (IndexError, ValueError):
            raise exceptions.CardNotFound()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号