Advertisement
tomdodd4598

Untitled

May 14th, 2021
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. import import_ipynb
  2.  
  3. from helpers import *
  4. from item import *
  5. from item_method_container import *
  6.  
  7. import re
  8.  
  9. valid_regex = "^(0|-?[1-9][0-9]*|[A-Za-z][0-9A-Z_a-z]*)$"
  10. number_regex = "^-?[0-9]+$"
  11.  
  12. def is_valid_string(_str):
  13.     return re.search(valid_regex, _str)
  14.  
  15. def is_number_string(_str):
  16.     return re.search(number_regex, _str)
  17.  
  18. class ItemMethodContainerString(ItemMethodContainer):
  19.     def insert_before(self, item, other):
  20.         if is_number_string(item.value) and is_number_string(other.value):
  21.             return int(item.value) <= int(other.value)
  22.         else:
  23.             return item.value <= other.value
  24.    
  25.     def value_equals(self, item, value):
  26.         return item.value == value
  27.  
  28. item_method_container_string = ItemMethodContainerString()
  29.  
  30. start = None
  31. begin = True
  32. _input = None
  33.  
  34. while True:
  35.     if not begin:
  36.         print()
  37.     else:
  38.         begin = False
  39.    
  40.     _input = input("Awaiting input...\n")
  41.    
  42.     if len(_input) == 0:
  43.         start = remove_all(start)
  44.         print("\nProgram terminated!")
  45.         break
  46.    
  47.     elif _input[0] == "~":
  48.         if len(_input) == 1:
  49.             print("\nDeleting list...")
  50.             start = remove_all(start)
  51.         else:
  52.             _input = _input[1:]
  53.             if is_valid_string(_input):
  54.                 print("\nRemoving item...")
  55.                 start = remove_item(start, _input)
  56.             else:
  57.                 print("\nCould not parse input!")
  58.    
  59.     elif _input == "l":
  60.         print("\nList print...")
  61.         print_list(start)
  62.    
  63.     elif _input == "i":
  64.         print("\nIterator print...")
  65.         print_iterator(start)
  66.    
  67.     elif _input == "a":
  68.         print("\nArray print...")
  69.         print_array(start)
  70.    
  71.     elif is_valid_string(_input):
  72.         print("\nInserting item...")
  73.         start = insert_item(start, _input, item_method_container_string)
  74.    
  75.     else:
  76.         print("\nCould not parse input!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement