This commit is contained in:
Patrik Tulach 2026-10-13 14:37:20 +02:00
parent 53907e290c
commit 16e3eb2d8c

25
u6/matching_brackets.py Normal file
View File

@ -0,0 +1,25 @@
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"))