Last active
March 10, 2018 05:57
-
-
Save jordanhudgens/8aee783d3ef7a50e36183532f0d37fb0 to your computer and use it in GitHub Desktop.
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 InfiniteLineup: | |
def __init__(self, players): | |
self.players = players | |
def lineup(self): | |
lineup_max = len(self.players) | |
idx = 0 | |
while True: | |
if idx < lineup_max: | |
yield self.players[idx] | |
else: | |
idx = 0 | |
yield self.players[idx] | |
idx += 1 | |
def __repr__(self): | |
return f'InfiniteLineup({self.players})' | |
def __str__(self): | |
return f"InfiniteLineup with the players: {', '.join(self.players)}" | |
astros = [ | |
'Springer', | |
'Bregman', | |
'Altuve', | |
'Correa', | |
'Reddick', | |
'Gonzalez', | |
'McCann', | |
'Davis', | |
'Tucker' | |
] | |
full_lineup = InfiniteLineup(astros) | |
astros_lineup = full_lineup.lineup() | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(next(astros_lineup)) | |
print(repr(full_lineup)) | |
print(str(full_lineup)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment