Skip to content

Instantly share code, notes, and snippets.

@hiAndrewQuinn
Created February 18, 2024 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiAndrewQuinn/c8d603be7a05cbfbe459b24872defbe7 to your computer and use it in GitHub Desktop.
Save hiAndrewQuinn/c8d603be7a05cbfbe459b24872defbe7 to your computer and use it in GitHub Desktop.
vector-of-pairs.py
class CustomList:
def __init__(self):
self.data = []
def store(self, first, second):
self.data.append((first, second))
def print(self, lookup):
def print_iter(lookup, dots=0):
print(".." * dots + str(lookup))
for first, second in self.data:
if first == lookup:
print_iter(second, dots + 1)
print_iter(lookup)
# Example usage
custom_list = CustomList()
custom_list.store(1, 2)
custom_list.store(1, 3)
custom_list.store(3, 4)
custom_list.store(4, 5)
print(custom_list.data)
custom_list.print(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment