Skip to content

Instantly share code, notes, and snippets.

@saumalya75
Last active August 22, 2020 14:16
Show Gist options
  • Save saumalya75/81eb79ac557230f8a61a9af0e02a89db to your computer and use it in GitHub Desktop.
Save saumalya75/81eb79ac557230f8a61a9af0e02a89db to your computer and use it in GitHub Desktop.
class House:
def __init__(self, name: str, symbol: str, student_list: list):
self.name = name
self.symbol = symbol
self.student_list = student_list
self.current_student_id = -1
def __len__(self):
return len(self.student_list)
def __next__(self):
self.current_student_id += 1
try:
return self.student_list[self.current_student_id]
except IndexError:
raise StopIteration()
def __iter__(self):
self.current_student_id = 0
return self
def __getitem__(self, item):
return self.student_list[item]
def __add__(self, other):
return self.student_list + other.student_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment