Created
March 20, 2018 22:32
-
-
Save jordanhudgens/b7fa0c68b10dc6a0f476296a257e42af 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 Lineup: | |
def __init__(self, players): | |
self.players = players | |
self.last_player_index = (len(self.players) - 1) | |
def __iter__(self): | |
self.n = 0 | |
return self | |
def get_player(self, n): | |
return self.players[n] | |
def __next__(self): | |
if self.n < self.last_player_index: | |
self.n += 1 | |
return self.get_player(self.n) | |
elif self.n == self.last_player_index: | |
self.n = 0 | |
return self.get_player(self.n) | |
astros = [ | |
'Springer', | |
'Bregman', | |
'Altuve', | |
'Correa', | |
'Reddick', | |
'Gonzalez', | |
'McCann', | |
'Davis', | |
'Tucker' | |
] | |
astros_lineup = Lineup(astros) | |
process = iter(astros_lineup) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) | |
print(next(process)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment