<commit_before>"""
    https://www.hackerrank.com/challenges/contacts/problem
    Problem:
        contact add and search operation
"""


class Node:
    def __init__(self, val):
        self.left = None
        self.right = None
        self.val = val


def create_trie(names):
    trie = dict()
    for name in names:
        current_dict = trie
        for char in name:
            if char in current_dict:
                tuple = current_dict[char]
            else:
                tuple = (1, dict())
            current_dict = current_dict.setdefault(char, {})
    return trie


print(create_trie(['add', 'ads', 'act']))<commit_msg>final solution with static input<commit_after>"""
    https://www.hackerrank.com/challenges/contacts/problem
    Problem:
        contact add and search operation
"""

def find(trie, z):
    res = 0
    current_dict = trie
    for i in z:
        if i in current_dict:
            res = current_dict[i][0]
            current_dict = current_dict[i][1]
        else :
            return 0
    return res


def create_trie(names):
    trie = dict()
    for name in names:
        current_dict = trie
        for char in name:
            if char in current_dict:
                tup = current_dict[char]  # TODO
                new_tup = (tup[0] + 1, tup[1])
                current_dict[char] = new_tup
            else:
                tup = (1, dict())
                current_dict[char] = tup
            current_dict = current_dict[char][1]
    return trie

result = create_trie(['add', 'bad', 'adder', 'ads'])
print(result)
# print(create_trie(['add', 'ads', 'act', 'bad']))
# print(find(result, 'add'))
print(find(result, 'ad'))
{'fraction_non_alphanumeric': 0.11894799760908548, 'fraction_numerical': 0.005977286312014346, 'mean_word_length': 1.9786476868327403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4527852', 'n_tokens_mistral': 538, 'n_tokens_neox': 517, 'n_words': 136}