Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a sample Python script.
- # Press Shift+F10 to execute it or replace it with your code.
- # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
- str_input = """add global a
- create foo global
- add foo b
- create bar foo
- add bar a
- """
- def main():
- n = int(input())
- namespaces_tree = dict()
- variables_in_namespaces = {"global": []}
- for x in range(n):
- command, namespace, var = input().split()
- if command == "add":
- variables_in_namespaces[namespace] += var
- elif command == "create":
- variables_in_namespaces[namespace] = []
- namespaces_tree[namespace] = var
- else:
- while namespace != "global" and var not in variables_in_namespaces[namespace]:
- namespace = namespaces_tree[namespace]
- if var not in variables_in_namespaces[namespace]:
- print("None")
- else:
- print(namespace)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement