Python
- 2 ответа
- 0 вопросов
1
Вклад в тег
def is_balanced(source, caps):
source = filter(lambda x: x in caps, source)
caps_dict = dict(zip(caps[::2], caps[1::2]))
stack = []
for cap in source:
if stack and cap == caps_dict.get(stack[-1], ""):
stack.pop()
else:
stack.append(cap)
return not stack
Note The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.
def add(dic):
globals().update(dic)
print(x+y)
add({'x': 2, 'y': 3})
print(x)
print(y)