Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import import_ipynb
- from helpers import *
- from item import *
- from item_method_container import *
- import re
- valid_regex = "^(0|-?[1-9][0-9]*|[A-Za-z][0-9A-Z_a-z]*)$"
- number_regex = "^-?[0-9]+$"
- def is_valid_string(_str):
- return re.search(valid_regex, _str)
- def is_number_string(_str):
- return re.search(number_regex, _str)
- class ItemMethodContainerString(ItemMethodContainer):
- def insert_before(self, item, other):
- if is_number_string(item.value) and is_number_string(other.value):
- return int(item.value) <= int(other.value)
- else:
- return item.value <= other.value
- def value_equals(self, item, value):
- return item.value == value
- item_method_container_string = ItemMethodContainerString()
- start = None
- begin = True
- _input = None
- while True:
- if not begin:
- print()
- else:
- begin = False
- _input = input("Awaiting input...\n")
- if len(_input) == 0:
- start = remove_all(start)
- print("\nProgram terminated!")
- break
- elif _input[0] == "~":
- if len(_input) == 1:
- print("\nDeleting list...")
- start = remove_all(start)
- else:
- _input = _input[1:]
- if is_valid_string(_input):
- print("\nRemoving item...")
- start = remove_item(start, _input)
- else:
- print("\nCould not parse input!")
- elif _input == "l":
- print("\nList print...")
- print_list(start)
- elif _input == "i":
- print("\nIterator print...")
- print_iterator(start)
- elif _input == "a":
- print("\nArray print...")
- print_array(start)
- elif is_valid_string(_input):
- print("\nInserting item...")
- start = insert_item(start, _input, item_method_container_string)
- else:
- print("\nCould not parse input!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement