u6
This commit is contained in:
parent
53907e290c
commit
16e3eb2d8c
25
u6/matching_brackets.py
Normal file
25
u6/matching_brackets.py
Normal 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"))
|
||||||
Loading…
Reference in New Issue
Block a user