From 0b232d3f2e6516374ffb09ea36ab4a2f2104a6f2 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 29 Jul 2022 09:32:02 +0430 Subject: update --- 890/main.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 890/main.py (limited to '890/main.py') diff --git a/890/main.py b/890/main.py new file mode 100755 index 0000000..2082679 --- /dev/null +++ b/890/main.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +from typing import List + + +class Solution: + @staticmethod + def findAndReplacePattern(words: List[str], pattern: str) -> List[str]: + def match(w): + m1, m2 = {}, {} + return all( + (m1.setdefault(i, j), m2.setdefault(j, i)) == (j, i) + for i, j in zip(w, pattern) + ) + + results = [] + for result in filter(match, words): + results.append(result) + return results + + +def main(): + words = ["abc", "deq", "mee", "aqq", "dkd", "ccc"] + pattern = "abb" + print(Solution.findAndReplacePattern(words, pattern)) + + +if __name__ == "__main__": + main() -- cgit v1.2.3