From 4631a9132613dabb26ba01dbf9d2ef770823d3ec Mon Sep 17 00:00:00 2001 From: SteliosGee Date: Mon, 30 Dec 2024 14:57:23 +0200 Subject: [PATCH 1/3] Add string utility functions: count vowels, check anagram, and remove punctuation --- public/data/python.json | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/public/data/python.json b/public/data/python.json index b4c9c2b0..5b6cb90e 100644 --- a/public/data/python.json +++ b/public/data/python.json @@ -28,6 +28,48 @@ ], "tags": ["python", "string", "palindrome", "utility"], "author": "dostonnabotov" + }, + { + "title": "Count Vowels", + "description": "Counts the number of vowels in a string.", + "code": [ + "def count_vowels(s):", + " vowels = 'aeiouAEIOU'", + " return len([char for char in s if char in vowels])", + "", + "# Usage:", + "print(count_vowels('hello')) # Output: 2" + ], + "tags": ["python", "string", "vowels", "count", "utility"], + "author": "SteliosGee" + }, + { + "title": "Check Anagram", + "description": "Checks if two strings are anagrams of each other.", + "code": [ + "def is_anagram(s1, s2):", + " return sorted(s1) == sorted(s2)", + "", + "# Usage:", + "print(is_anagram('listen', 'silent')) # Output: True" + ], + "tags": ["python", "string", "anagram", "check", "utility"], + "author": "SteliosGee" + }, + { + "title": "Remove Punctuation", + "description": "Removes punctuation from a string.", + "code": [ + "import string", + "", + "def remove_punctuation(s):", + " return s.translate(str.maketrans('', '', string.punctuation))", + "", + "# Usage:", + "print(remove_punctuation('Hello, World!')) # Output: 'Hello World'" + ], + "tags": ["python", "string", "punctuation", "remove", "utility"], + "author": "SteliosGee" } ] }, From 16302af46ff5bb0c6dd9d105335c0d9eb11511a1 Mon Sep 17 00:00:00 2001 From: SteliosGee Date: Mon, 30 Dec 2024 23:03:00 +0200 Subject: [PATCH 2/3] Fix count_vowels function to handle uppercase letters by converting input to lowercase --- public/data/python.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/data/python.json b/public/data/python.json index 5b6cb90e..a47de943 100644 --- a/public/data/python.json +++ b/public/data/python.json @@ -35,7 +35,7 @@ "code": [ "def count_vowels(s):", " vowels = 'aeiouAEIOU'", - " return len([char for char in s if char in vowels])", + " return len([char for char in s.lower() if char in vowels])", "", "# Usage:", "print(count_vowels('hello')) # Output: 2" From 32c722c8ce87a101010f4b739542a98a1a2d73af Mon Sep 17 00:00:00 2001 From: SteliosGee Date: Mon, 30 Dec 2024 23:40:32 +0200 Subject: [PATCH 3/3] Changed --- public/data/python.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/data/python.json b/public/data/python.json index a47de943..ff91bd96 100644 --- a/public/data/python.json +++ b/public/data/python.json @@ -34,7 +34,7 @@ "description": "Counts the number of vowels in a string.", "code": [ "def count_vowels(s):", - " vowels = 'aeiouAEIOU'", + " vowels = 'aeiou'", " return len([char for char in s.lower() if char in vowels])", "", "# Usage:",