andewK

Untitled

May 17th, 2021
622
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def main():
  2.     n = int(input())
  3.     namespaces_tree = dict()
  4.  
  5.     variables_in_namespaces = {"global": []}
  6.  
  7.     for x in range(n):
  8.         command, namespace, var = input().split()
  9.         if command == "add":
  10.             variables_in_namespaces[namespace] += [var]
  11.         elif command == "create":
  12.             variables_in_namespaces[namespace] = []
  13.             namespaces_tree[namespace] = var
  14.         else:
  15.             while namespace != "global" and var not in variables_in_namespaces[namespace]:
  16.                 namespace = namespaces_tree[namespace]
  17.             if var not in variables_in_namespaces[namespace]:
  18.                 print("None")
  19.             else:
  20.                 print(namespace)
  21.  
  22.  
  23. if __name__ == '__main__':
  24.     main()
  25.  
  26.  
RAW Paste Data