Exercise 3: A Comment Containing a Literal '<' — Possible Solution ==================================================================== THE TEST ------------------------------ tokenize("

after

") RESULT ------------------------------ [comment(' a < b '), opentag('p', {}), text('after'), closetag('p')] The comment's own text is exactly ' a < b ' -- the literal '<' character preserved as ordinary comment content -- and the following

element tokenizes completely normally afterward. WHICH PART OF tokenize HANDLES THIS ------------------------------ if html.startswith('', i + 4) comment_text = html[i+4:end] i = end + 3 tokens.append(Token('comment', text=comment_text)) continue The key line is `end = html.find('-->', i + 4)`. Once the main loop recognizes the four-character sequence "' anywhere after this point." That search has no separate awareness of '<' or '>' as individually meaningful characters at all -- it's looking for one exact substring, full stop. The stray '<' in " a < b " is just one character among many sitting inside the range being copied into comment_text; it's never inspected on its own by anything that treats '<' as "the start of a tag," because that logic lives entirely in the OUTER while loop (`if html[i] != '<': i += 1; continue`), which this comment-handling branch never returns to until after `i` has already been advanced past the full "-->" delimiter. WHY THIS WORKS AS AN ANSWER ------------------------------ This is the same underlying design the chapter's own '>' example demonstrates, just triggered by the other character a naive scanner might reasonably assume is special. Both cases confirm the same thing: once inside a comment, the tokenizer's own notion of "what counts as a delimiter" narrows to exactly one specific string ('-->'), and every other character -- including the two characters that are normally the most structurally significant in the entire format -- is just data until that string is found.