26 lines
517 B
Python
26 lines
517 B
Python
def is_paired(input_string):
|
|
open = '({['
|
|
close = ')}]'
|
|
|
|
search = []
|
|
|
|
for chr in input_string:
|
|
if chr in open:
|
|
search.append(close[open.index(chr)])
|
|
continue
|
|
|
|
if chr in (open + close):
|
|
if search:
|
|
if chr != search[-1]:
|
|
return False
|
|
else:
|
|
search.pop(-1)
|
|
else:
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
print(is_paired("() a[]b()c{[} [fds]gh"))
|