diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2023-05-10 17:09:33 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2023-05-10 17:09:33 +0100 |
| commit | bb52405967e3387c63e9fffd0a2bd82678882f40 (patch) | |
| tree | 88eba058d26136d2a86dcc77982f42cdc245bdf6 /challenge-216/manfredi/python | |
| parent | 2e943784a5c321b375ba33ab415a70dcf030b61c (diff) | |
| parent | 722527ed475e56e5717e60f8d3b52d9bbcef492c (diff) | |
| download | perlweeklychallenge-club-bb52405967e3387c63e9fffd0a2bd82678882f40.tar.gz perlweeklychallenge-club-bb52405967e3387c63e9fffd0a2bd82678882f40.tar.bz2 perlweeklychallenge-club-bb52405967e3387c63e9fffd0a2bd82678882f40.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-216/manfredi/python')
| -rwxr-xr-x | challenge-216/manfredi/python/ch-1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-216/manfredi/python/ch-1.py b/challenge-216/manfredi/python/ch-1.py new file mode 100755 index 0000000000..fcee0dbc5d --- /dev/null +++ b/challenge-216/manfredi/python/ch-1.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# Python 3.9.2 on Debian GNU/Linux 11 (bullseye) + +print('challenge-216-task1') + +# Task 1: Registration Number +# You are given a list of words and a random registration number. +# Write a script to find all the words in the given list that has every letter in the given registration number. + +# Example 1 +# Input: @words = ('abc', 'abcd', 'bcd'), $reg = 'AB1 2CD' +# Output: ('abcd') + +# Example 2 +# Input: @words = ('job', 'james', 'bjorg'), $reg = '007 JB' +# Output: ('job', 'bjorg') + +# Example 3 +# Input: @words = ('crack', 'road', 'rac'), $reg = 'C7 RA2' +# Output: ('crack', 'rac') + +def registration_number(reg: str, words: list[str]) -> list[str]: + out = [] + print(f"Input: words = ({words}), reg = '{reg}'") + r = set( [ i for i in reg.lower() if i.isalpha() ]) + for word in words: + w = set(word.lower()) + if r.issubset(w): out.append(word) + return out + + +def main(): + print("Output: ", registration_number('AB1 2CD', ['abc', 'abcd', 'bcd']), "\n") + print("Output: ", registration_number('007 JB', ['job', 'james', 'bjorg']), "\n") + print("Output: ", registration_number('C7 RA2', ['crack', 'road', 'rac']), "\n") + + +if __name__ == '__main__': + main() |
