andewK

Untitled

May 17th, 2021
575
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This is a sample Python script.
  2.  
  3. # Press Shift+F10 to execute it or replace it with your code.
  4. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
  5.  
  6. str_input = """add global a
  7. create foo global
  8. add foo b
  9. create bar foo
  10. add bar a
  11. """
  12.  
  13.  
  14. def main():
  15.     n = int(input())
  16.     namespaces_tree = dict()
  17.  
  18.     variables_in_namespaces = {"global": []}
  19.  
  20.     for x in range(n):
  21.         command, namespace, var = input().split()
  22.         if command == "add":
  23.             variables_in_namespaces[namespace] += var
  24.         elif command == "create":
  25.             variables_in_namespaces[namespace] = []
  26.             namespaces_tree[namespace] = var
  27.         else:
  28.             while namespace != "global" and var not in variables_in_namespaces[namespace]:
  29.                 namespace = namespaces_tree[namespace]
  30.             if var not in variables_in_namespaces[namespace]:
  31.                 print("None")
  32.             else:
  33.                 print(namespace)
  34.  
  35.  
  36. if __name__ == '__main__':
  37.     main()
  38.  
RAW Paste Data