class TrieNode:
    def __init__(self):
        # Initialize this node in the Trie
        self.is_word = False
        self.children = {}

    def insert(self, char):
        # Add a child node in this Trie
        self.children[char] = TrieNode()

    def suffixes(self, prefix=""):
        generated = self.generate_suffixes(prefix)
        return ",".join(generated)

    def generate_suffixes(self, prefix):
        if self.is_word:
            yield prefix

        for char, node in self.children.items():
            yield from node.generate_suffixes(prefix + char)


# The Trie itself containing the root node and insert/find functions
class Trie:
    def __init__(self):
        # Initialize this Trie (add a root node)
        self.root = TrieNode()

    def insert(self, word):
        # Add a word to the Trie
        node = self.root

        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]

        node.is_word = True

    def find(self, prefix):
        # Find the Trie node that represents this prefix
        node = self.root

        for char in prefix:
            if char not in node.children:
                return None
            node = node.children[char]

        return node


MyTrie = Trie()
wordList = [
    "ant",
    "anthology",
    "antagonist",
    "antonym",
    "fun",
    "function",
    "factory",
    "trie",
    "trigger",
    "trigonometry",
    "tripod",
]
for word in wordList:
    MyTrie.insert(word)

MyTrie = Trie()
wordList = [
    "ant", "anthology", "antagonist", "antonym",
    "fun", "function", "factory",
    "trie", "trigger", "trigonometry", "tripod"
]
for word in wordList:
    MyTrie.insert(word)

print(MyTrie.find("ant").suffixes())  # ,hology,agonist,onym
print(MyTrie.find("f").suffixes())  # un,unction,actory
print(MyTrie.find("t").suffixes())  # rie,rigger,rigonometry,ripod
print(MyTrie.find("trig").suffixes())  # ger,onometry

9e03e2b9f696209062240809ba6e19f57b361e0f
class TrieNode:
    <mask token>
    <mask token>
    <mask token>

    def generate_suffixes(self, prefix):
        if self.is_word:
            yield prefix
        for char, node in self.children.items():
            yield from node.generate_suffixes(prefix + char)


class Trie:

    def __init__(self):
        self.root = TrieNode()

    def insert(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]
        node.is_word = True

    def find(self, prefix):
        node = self.root
        for char in prefix:
            if char not in node.children:
                return None
            node = node.children[char]
        return node


<mask token>

class TrieNode:

    def __init__(self):
        self.is_word = False
        self.children = {}
    <mask token>
    <mask token>

    def generate_suffixes(self, prefix):
        if self.is_word:
            yield prefix
        for char, node in self.children.items():
            yield from node.generate_suffixes(prefix + char)


class Trie:

    def __init__(self):
        self.root = TrieNode()

    def insert(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]
        node.is_word = True

    def find(self, prefix):
        node = self.root
        for char in prefix:
            if char not in node.children:
                return None
            node = node.children[char]
        return node


<mask token>

class TrieNode:

    def __init__(self):
        self.is_word = False
        self.children = {}

    def insert(self, char):
        self.children[char] = TrieNode()

    def suffixes(self, prefix=''):
        generated = self.generate_suffixes(prefix)
        return ','.join(generated)

    def generate_suffixes(self, prefix):
        if self.is_word:
            yield prefix
        for char, node in self.children.items():
            yield from node.generate_suffixes(prefix + char)


class Trie:

    def __init__(self):
        self.root = TrieNode()

    def insert(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]
        node.is_word = True

    def find(self, prefix):
        node = self.root
        for char in prefix:
            if char not in node.children:
                return None
            node = node.children[char]
        return node


<mask token>

class TrieNode:

    def __init__(self):
        self.is_word = False
        self.children = {}

    def insert(self, char):
        self.children[char] = TrieNode()

    def suffixes(self, prefix=''):
        generated = self.generate_suffixes(prefix)
        return ','.join(generated)

    def generate_suffixes(self, prefix):
        if self.is_word:
            yield prefix
        for char, node in self.children.items():
            yield from node.generate_suffixes(prefix + char)


class Trie:

    def __init__(self):
        self.root = TrieNode()

    def insert(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]
        node.is_word = True

    def find(self, prefix):
        node = self.root
        for char in prefix:
            if char not in node.children:
                return None
            node = node.children[char]
        return node


<mask token>
for word in wordList:
    MyTrie.insert(word)
<mask token>
for word in wordList:
    MyTrie.insert(word)
print(MyTrie.find('ant').suffixes())
print(MyTrie.find('f').suffixes())
print(MyTrie.find('t').suffixes())
print(MyTrie.find('trig').suffixes())

class TrieNode:
    def __init__(self):
        # Initialize this node in the Trie
        self.is_word = False
        self.children = {}

    def insert(self, char):
        # Add a child node in this Trie
        self.children[char] = TrieNode()

    def suffixes(self, prefix=""):
        generated = self.generate_suffixes(prefix)
        return ",".join(generated)

    def generate_suffixes(self, prefix):
        if self.is_word:
            yield prefix

        for char, node in self.children.items():
            yield from node.generate_suffixes(prefix + char)


# The Trie itself containing the root node and insert/find functions
class Trie:
    def __init__(self):
        # Initialize this Trie (add a root node)
        self.root = TrieNode()

    def insert(self, word):
        # Add a word to the Trie
        node = self.root

        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]

        node.is_word = True

    def find(self, prefix):
        # Find the Trie node that represents this prefix
        node = self.root

        for char in prefix:
            if char not in node.children:
                return None
            node = node.children[char]

        return node


MyTrie = Trie()
wordList = [
    "ant",
    "anthology",
    "antagonist",
    "antonym",
    "fun",
    "function",
    "factory",
    "trie",
    "trigger",
    "trigonometry",
    "tripod",
]
for word in wordList:
    MyTrie.insert(word)

MyTrie = Trie()
wordList = [
    "ant", "anthology", "antagonist", "antonym",
    "fun", "function", "factory",
    "trie", "trigger", "trigonometry", "tripod"
]
for word in wordList:
    MyTrie.insert(word)

print(MyTrie.find("ant").suffixes())  # ,hology,agonist,onym
print(MyTrie.find("f").suffixes())  # un,unction,actory
print(MyTrie.find("t").suffixes())  # rie,rigger,rigonometry,ripod
print(MyTrie.find("trig").suffixes())  # ger,onometry
