aboutsummaryrefslogtreecommitdiff
path: root/challenge-330/ysth/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-07-20 23:55:03 +0100
committerGitHub <noreply@github.com>2025-07-20 23:55:03 +0100
commit240017751fa3e9e9298378ea8d54b0e7f9f319e2 (patch)
tree43f0a18ee9a7a13e3dc2d0f174541ad379d03813 /challenge-330/ysth/python
parenta0c0cf2507542ca8fc6eec5d6a84d2ae5dc21d12 (diff)
parentc59c514f141986ca1c98e32d44f6ad37bf15b28c (diff)
downloadperlweeklychallenge-club-240017751fa3e9e9298378ea8d54b0e7f9f319e2.tar.gz
perlweeklychallenge-club-240017751fa3e9e9298378ea8d54b0e7f9f319e2.tar.bz2
perlweeklychallenge-club-240017751fa3e9e9298378ea8d54b0e7f9f319e2.zip
Merge pull request #12376 from ysth/challenge-330-ysth
challenge 330 python, perl, and go solutions
Diffstat (limited to 'challenge-330/ysth/python')
-rw-r--r--challenge-330/ysth/python/ch-1.py14
-rw-r--r--challenge-330/ysth/python/ch-2.py17
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-330/ysth/python/ch-1.py b/challenge-330/ysth/python/ch-1.py
new file mode 100644
index 0000000000..13f8df9546
--- /dev/null
+++ b/challenge-330/ysth/python/ch-1.py
@@ -0,0 +1,14 @@
+import sys
+import regex
+
+def clear_digits(string: str) -> str:
+ return regex.sub(r'[0-9]*(?<pair>[a-z](?&pair)?[0-9])*', '', string)
+
+def main() -> None:
+ inputs: list[str] = sys.argv[1:]
+
+ for string in inputs:
+ print(f'{string:<30} -> {clear_digits(string)}')
+
+if __name__ == '__main__':
+ main()
diff --git a/challenge-330/ysth/python/ch-2.py b/challenge-330/ysth/python/ch-2.py
new file mode 100644
index 0000000000..0b3f0ae6fa
--- /dev/null
+++ b/challenge-330/ysth/python/ch-2.py
@@ -0,0 +1,17 @@
+import sys
+import grapheme
+
+def grapheme_length_more_than_2(string: str) -> bool:
+ return grapheme.length(string, 3) > 2
+
+def title_capital(string: str) -> str:
+ return ' '.join( word.capitalize() if grapheme_length_more_than_2(word) else word.lower() for word in string.split(' ') )
+
+def main() -> None:
+ inputs: list[str] = sys.argv[1:]
+
+ for string in inputs:
+ print(f'{string:<30} -> {title_capital(string)}')
+
+if __name__ == '__main__':
+ main()