Skip to content
Snippets Groups Projects
Commit b9ad24c3 authored by nilsl99's avatar nilsl99
Browse files

Implemented check_klammern

parent 2ee34a95
No related branches found
No related tags found
No related merge requests found
from Aufgabe03a import Stack
def end(c):
if c == "(": return ")"
if c == "[": return "]"
if c == "<": return ">"
if c == "{": return "}"
return None
def check_klammern(s):
check_sum = Stack()
for c in s:
if c in ["(", "[", "<", "{"]:
check_sum.push(c)
elif c in [")", "]", ">", "}"]:
if check_sum.isEmpty():
return False
elif c == end(check_sum.pop()):
continue
else:
return False
return check_sum.isEmpty()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment