Skip to content

Instantly share code, notes, and snippets.

@DiogenesAnalytics
Created December 6, 2023 17:43
Show Gist options
  • Save DiogenesAnalytics/6e36b00b2f8f28835679e19d2e1a8e2c to your computer and use it in GitHub Desktop.
Save DiogenesAnalytics/6e36b00b2f8f28835679e19d2e1a8e2c to your computer and use it in GitHub Desktop.
Fluent Python Select Examples
import collections
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment