Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Namespaces:
- def __init__(self):
- self.namespace_set = set()
- self.general_dictionary = {'global': ('None', {}, set())}
- def create_namespase_into_parent(self, dictionary_name, namespace_name, parent_namespace_name):
- for key, value in dictionary_name.items():
- if key == parent_namespace_name:
- dictionary_of_namespases = value[1]
- namespace_set.add(namespace_name)
- dictionary_of_namespases[namespace_name]=(parent_namespace_name,{},set())
- else:
- dictionary_of_namespases = value[1]
- self.create_namespase_into_parent(dictionary_of_namespases, namespace_name, parent_namespace_name)
- def add_to_namespace_new_variable(self, dictionary_name, namespace_name, variable_name):
- for key, value in dictionary_name.items():
- if key == namespace_name:
- set_of_variables = value[2]
- set_of_variables.add(variable_name)
- else:
- dictionary_of_namespases = value[1]
- self.add_to_namespace_new_variable(dictionary_of_namespases, namespace_name, variable_name)
- def get_variable_from_namespace(self, dictionary, namespace_name, variable_name):
- for key, value in dictionary.items():
- if key != namespace_name:
- dictionary_of_namespases = value[1]
- self.get_variable_from_namespace(dictionary_of_namespases, namespace_name, variable_name)
- else:
- set_of_variables = value[2]
- if variable_name in set_of_variables:
- print(namespace_name)
- else:
- name_of_parent = value[0]
- if (name_of_parent == 'None'):
- print(None)
- else:
- self.get_variable_from_namespace(self.general_dictionary, name_of_parent, variable_name)
- x = Namespaces()
- x.namespace_set.add('global')
- number_of_requests = int(input())
- for item in range(number_of_requests):
- command, namespace, argument = input().split()
- if command == 'create':
- namespace_set = x.namespace_set
- if namespace not in namespace_set:
- x.create_namespase_into_parent(x.general_dictionary, namespace, argument)
- if command == 'add':
- x.add_to_namespace_new_variable(x.general_dictionary, namespace, argument)
- if command == 'get':
- if namespace in x.namespace_set:
- x.get_variable_from_namespace(x.general_dictionary, namespace, argument)
- else:
- print(None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement