Skip to content

Instantly share code, notes, and snippets.

@tjarratt
Created July 19, 2023 15:06
Show Gist options
  • Save tjarratt/2e28c378498e4fe8e8058e1f23b7b887 to your computer and use it in GitHub Desktop.
Save tjarratt/2e28c378498e4fe8e8058e1f23b7b887 to your computer and use it in GitHub Desktop.
A set that can be iterated
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