Encrypt and Decrypt Strings LeetCode solution in Python
1class Encrypter:23def __init__(self, keys: List[str], values: List[str], dictionary: List[str]):4self.hashmap = dict()5for i in range(len(keys)):6self.hashmap[keys[i]] = values[i]7self.dictmap = defaultdict(int)8for word in dictionary:9self.dictmap[self.encrypt(word)] += 11011def encrypt(self, word1: str) -> str:12output = ""13for char in word1:14output += self.hashmap[char]15return output1617def decrypt(self, word2: str) -> int:18return self.dictmap[word2]