diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-10-01 20:20:39 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-10-01 20:20:39 +0200 |
| commit | 8fa2bf1ea409b61d0406205c0ff9097961981a6b (patch) | |
| tree | 1ad48b8b8008b0bb1bd83fcf32206acebf4643b6 | |
| parent | b505fe32ab56d20d7c40913a2748cd1692fc633e (diff) | |
| download | perlweeklychallenge-club-8fa2bf1ea409b61d0406205c0ff9097961981a6b.tar.gz perlweeklychallenge-club-8fa2bf1ea409b61d0406205c0ff9097961981a6b.tar.bz2 perlweeklychallenge-club-8fa2bf1ea409b61d0406205c0ff9097961981a6b.zip | |
feat(challenge-184/lubos-kolouch/python/ch-{1,2}.py): Challenge 184 Task 1 2 LK Python
| -rw-r--r-- | challenge-184/lubos-kolouch/python/ch-1.py | 20 | ||||
| -rw-r--r-- | challenge-184/lubos-kolouch/python/ch-2.py | 43 |
2 files changed, 63 insertions, 0 deletions
diff --git a/challenge-184/lubos-kolouch/python/ch-1.py b/challenge-184/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..6308218106 --- /dev/null +++ b/challenge-184/lubos-kolouch/python/ch-1.py @@ -0,0 +1,20 @@ +""" Challenge 184 Task 1""" + + +def replace_chars(my_input: list) -> list: + """Do the exercise""" + + output = [] + + for pos, item in enumerate(my_input): + + # assuming to rotate the sequence if more than 100 words + next_item = f"{pos % 100:02d}" + + output.append(next_item + item[2:]) + + return output + + +assert replace_chars(["ab1234", "cd5678", "ef1342"]) == ["001234", "015678", "021342"] +assert replace_chars(["pq1122", "rs3334"]) == ["001122", "013334"] diff --git a/challenge-184/lubos-kolouch/python/ch-2.py b/challenge-184/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..dd601098b5 --- /dev/null +++ b/challenge-184/lubos-kolouch/python/ch-2.py @@ -0,0 +1,43 @@ +""" Challenge 184 Task 2""" +import re + + +def split_array(my_input: list) -> list: + """Do the task""" + + list09 = [] + listaz = [] + + for item in my_input: + + temp09 = [] + tempaz = [] + + for char in item: + + if re.match(r"\d", char): + temp09.append(int(char)) + + if re.match(r"[a-z]", char): + tempaz.append(char) + + # ignore if there is some other garbage + + if temp09: + list09.append(temp09) + + if tempaz: + listaz.append(tempaz) + + return [list09, listaz] + + +assert split_array(["a 1 2 b 0", "3 c 4 d"]) == [ + [[1, 2, 0], [3, 4]], + [["a", "b"], ["c", "d"]], +] + +assert split_array(["1 2", "p q r", "s 3", "4 5 t"]) == [ + [[1, 2], [3], [4, 5]], + [["p", "q", "r"], ["s"], ["t"]], +] |
