I keep coming up with a syntax error:
File "", line 12 else tag == s.peek(): ^ SyntaxError: invalid syntax
def check_html(html_string): balanced = True s = Stack() text_lines = html_string.split("\n") for line in text_lines: # line can be something like <html> or </body> if "/" in line: # a close tag tag = line.replace("<", "").replace(">", "").replace(...) if s.is_empty(): balanced = False # should be invalid elif tag == s.peek(): # should be valid and pop else: # should be invalid elif "<" in line: # an open tag tag = line.replace("<", "").replace(">", "") s.push(tag) if not s.is_empty(): # should be invalid return balanced
Any input that might lead me in a better direction?
https://stackoverflow.com/questions/67238586/i-am-using-python-to-create-a-check-html-function-for-validation-using-a-stack April 24, 2021 at 09:35AM
没有评论:
发表评论