def get(self, term, limit=0, sort=False, ranks=None): """ Get the specified card from the stack. :arg term: The search term. Can be a card full name, value, suit, abbreviation, or stack indice. :arg int limit: The number of items to retrieve for each term. :arg bool sort: Whether or not to sort the results, by poker ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: A list of the specified cards, if found. """ ranks = ranks or self.ranks got_cards = [] try: indices = self.find(term, limit=limit) got_cards = [self.cards[i] for i in indices] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] except: got_cards = [self.cards[term]] self.cards = [v for i, v in enumerate(self.cards) if i is not term] if sort: got_cards = sort_cards(got_cards, ranks) return got_cards
def get_list(self, terms, limit=0, sort=False, ranks=None): """ Get the specified cards from the stack. :arg term: The search term. Can be a card full name, value, suit, abbreviation, or stack indice. :arg int limit: The number of items to retrieve for each term. :arg bool sort: Whether or not to sort the results, by poker ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: A list of the specified cards, if found. """ ranks = ranks or self.ranks got_cards = [] try: indices = self.find_list(terms, limit=limit) got_cards = [ self.cards[i] for i in indices if self.cards[i] not in got_cards ] self.cards = [ v for i, v in enumerate(self.cards) if i not in indices ] except: indices = [] for item in terms: try: card = self.cards[item] if card not in got_cards: got_cards.append(card) indices.append(item) except: indices += self.find(item, limit=limit) got_cards += [ self.cards[i] for i in indices if self.cards[i] not in got_cards ] self.cards = [ v for i, v in enumerate(self.cards) if i not in indices ] if sort: got_cards = sort_cards(got_cards, ranks) return got_cards
def sort(self, ranks=None): """ Sorts the stack, either by poker ranks, or big two ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted cards. """ ranks = ranks or self.ranks self.cards = sort_cards(self.cards, ranks)