diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-10 11:50:45 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-10 11:50:45 +0100 |
| commit | 722527ed475e56e5717e60f8d3b52d9bbcef492c (patch) | |
| tree | 81befdc86fae021847066ce54b4a56d554c45ec3 /challenge-216/lubos-kolouch/python/ch-1.py | |
| parent | c265c11df5b158f65eb8699298fd6a9b89467ce7 (diff) | |
| download | perlweeklychallenge-club-722527ed475e56e5717e60f8d3b52d9bbcef492c.tar.gz perlweeklychallenge-club-722527ed475e56e5717e60f8d3b52d9bbcef492c.tar.bz2 perlweeklychallenge-club-722527ed475e56e5717e60f8d3b52d9bbcef492c.zip | |
- Added solutions by Lubos Kolouch.
- Added solutions by Robert DiCicco.
- Added solutions by W. Luis Mochan.
Diffstat (limited to 'challenge-216/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-216/lubos-kolouch/python/ch-1.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-216/lubos-kolouch/python/ch-1.py b/challenge-216/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..c52a4df31f --- /dev/null +++ b/challenge-216/lubos-kolouch/python/ch-1.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from typing import List + + +def matching_words(words: List[str], reg: str) -> List[str]: + reg = reg.upper() + letters = set(letter for letter in reg if letter.isalpha()) + matches = [] + for word in words: + upper_word = word.upper() + matched = all(letter in upper_word for letter in letters) + if matched: + matches.append(word) + return matches + + +words = ['job', 'james', 'bjorg'] +reg = '007 JB' +matches_list = matching_words(words, reg) +print("(", ", ".join(f"'{match}'" for match in matches_list), ")") |
