#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1070
Task: Write a Python function that implements a trie (prefix tree) with insert and search
Generated: 2026-02-12T19:00:52.736156
"""

class TrieNode:
    def __init__(self):
        self.children = {}
        self.is_end = False


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_end = True

    def search(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                return False
            node = node.children[char]
        return node.is_end


if __name__ == '__main__':
    trie = Trie()
    words_to_insert = ["apple", "app", "apply", "banana"]
    for word in words_to_insert:
        trie.insert(word)

    test_words = ["apple", "app", "apply", "banana", "bananas", "grape"]
    for word in test_words:
        result = trie.search(word)
        print(f"Word '{word}': Found = {result}")