Created
July 19, 2023 15:06
-
-
Save tjarratt/2e28c378498e4fe8e8058e1f23b7b887 to your computer and use it in GitHub Desktop.
A set that can be iterated
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 ListSet: | |
def __init__(self): | |
self._values = [] | |
self.__index = 0 | |
def add(self, value): | |
if value in self._values: | |
return | |
self._values.append(value) | |
def __iter__(self): | |
return self | |
def __next__(self): | |
if self.__index >= len(self._values): | |
raise StopIteration() | |
val = self._values[self.__index] | |
self.__index += 1 | |
return val | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment