-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.4.py
More file actions
48 lines (37 loc) · 1.04 KB
/
1.4.py
File metadata and controls
48 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespaces = {'global': 'None'}
variables = {}
variables['global'] = []
command=[]
def read():
n = int(input())
global command
for i in range(n):
command.append(input().split())
def processed():
global command
for c in command:
if c[0] == 'create':
create_namespace(c[1], c[2])
if c[0] == 'add':
add_var(c[1], c[2])
if c[0] == 'get':
print(get(c[1], c[2]))
def create_namespace(name, parent):
namespaces[name]=parent
variables[name]=[]
def add_var(namespace, name):
variables[namespace].append(name)
def get (space, var):
current_space = space
if var in variables[current_space]:
return current_space
else:
current_space = namespaces[current_space]
if current_space is 'None':
return 'None'
else:
return get(current_space,var)
read()
processed()
# namespaces = {'global': 'None', 'foo': 'global', 'bar': 'foo'}
# variables = {'global': ['a'], 'foo': ['b'], 'bar': ['a', 'c', 'd']}