Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IList:
- def __init__(self):
- self.item = None
- self.next = None
- def __add__(self, item):
- new_item = IList()
- new_item.item = item
- new_item.next = self
- return new_item
- def __getitem__(self, index):
- if index == 0:
- return self.item
- else:
- return self.next[index - 1]
- Nil = IList()
- my_list = Nil + 1 + 5 + 7 + 15 + 10
- print(my_list[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement