Created
April 8, 2014 23:28
-
-
Save ramalho/10208462 to your computer and use it in GitHub Desktop.
Solução do Daniel Bastos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import shuffle | |
| class Tombola(object): | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) | |
| def misturar(self, pairswap=None): | |
| pairswap(self.itens) if pairswap else shuffle(self.itens) # LR: funciona mas é melhor testar explicitamente arg is None | |
| def sortear(self): | |
| return self.itens.pop() | |
| def carregada(self): | |
| return bool(self.itens) | |
| def __iter__(self): | |
| for i in reversed(self.itens): | |
| yield i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Tombola(object): | |
| '''IMPLEMENTACAO COM BUG!!!''' # LR: consertado pelo Daniel Bastos | |
| def __init__(self, seq): | |
| self.itens = list(seq) # LR: era isso mesmo! | |
| def carregar(self, seq): | |
| self.itens.extend(seq) | |
| def sortear(self): | |
| return self.itens.pop() | |
| def carregada(self): | |
| return bool(self.itens) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment