From 4631a9132613dabb26ba01dbf9d2ef770823d3ec Mon Sep 17 00:00:00 2001 From: SteliosGee Date: Mon, 30 Dec 2024 14:57:23 +0200 Subject: [PATCH] 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" } ] },