Fix matching brackets implementation
This commit is contained in:
parent
7f81fa7032
commit
b8252195f1
12
u6/matching_brackets.py
Normal file
12
u6/matching_brackets.py
Normal file
@ -0,0 +1,12 @@
|
||||
def is_paired(input_string):
|
||||
spisok = []
|
||||
slovnik = {')': '(', ']': '[', '}': '{'}
|
||||
|
||||
for gnx in input_string:
|
||||
if gnx in "([{":
|
||||
spisok.append(gnx)
|
||||
elif gnx in ")]}":
|
||||
if not spisok or spisok[-1] != slovnik[gnx]:
|
||||
return False
|
||||
spisok.pop()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user