aboutsummaryrefslogblamecommitdiffstats
path: root/890/main.py
blob: 10aa9e6e32f7b27450c4005bf875da28cf5dece9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10







                                                                           

                               
                       

                                                                        















                                                         
#!/usr/bin/env python3

from typing import List


class Solution:
    @staticmethod
    def findAndReplacePattern(words: List[str], pattern: str) -> List[str]:
        def match(word):
            map1, map2 = {}, {}
            return all(
                (map1.setdefault(i, j), map2.setdefault(j, i)) == (j, i)
                for i, j in zip(word, 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()