Clean Python 3, generator and trie
Time: O(N), where N is the length of input text\nSpace: O(N + E) for output string and trie, where E is the total length of entities\n\nclass Solution:\n    def
Time: `O(N)`, where `N` is the length of input `text`\nSpace: `O(N + E)` for output string and trie, where `E` is the total length of entities\n```\nclass Solution:\n    def entityParser(self, text: str) -> str:\n        def add(entity: str, symbol: str):\n            node = trie\n            for c in entity:\n                node = node.setdefault(c, {})\n            node[\'#\'] = symbol\n\n        def check(idx: int) -> tuple:\n            node = trie\n            while text[idx] in node:\n                node = node[text[idx]]\n                idx += 1\n                if \'#\' in node: return node[\'#\'], idx\n            return False, idx\n\n        def parse():\n            i = 0\n            while i < len(text):\n                if text[i] in trie:\n                    symbol, j = check(i)\n                    yield symbol or text[i:j]\n                    i = j\n                else:\n                    yield text[i]\n                    i += 1\n\n        trie = {}\n        entities = [(\'&quot;\', \'"\'), (\'&apos;\', "\'"), (\'&amp;\', \'&\'), (\'&gt;\', \'>\'), (\'&lt;\', \'<\'), (\'&frasl;\', \'/\')]\n        for entity, symbol in entities:\n            add(entity, symbol)\n        return \'\'.join(parse())\n```
['Trie', 'Python3']