Created
February 18, 2024 08:34
-
-
Save hiAndrewQuinn/c8d603be7a05cbfbe459b24872defbe7 to your computer and use it in GitHub Desktop.
vector-of-pairs.py
This file contains 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 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