From 722527ed475e56e5717e60f8d3b52d9bbcef492c Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 10 May 2023 11:50:45 +0100 Subject: - Added solutions by Lubos Kolouch. - Added solutions by Robert DiCicco. - Added solutions by W. Luis Mochan. --- challenge-216/lubos-kolouch/python/ch-1.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-216/lubos-kolouch/python/ch-1.py (limited to 'challenge-216/lubos-kolouch/python/ch-1.py') 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), ")") -- cgit