From 802eca4ffdd38aa21f203080d3cd20cc6388a81d Mon Sep 17 00:00:00 2001 From: Rohit Tanwar Date: Tue, 9 Jan 2018 14:27:03 +0530 Subject: [PATCH] vowels --- README.md | 19 +++++++++++++++++++ snippets/countVowels.md | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 snippets/countVowels.md diff --git a/README.md b/README.md index 39cfbf751..06bcd10ab 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,25 @@ def countOccurences(arr, val): ```python countOccurrences([1, 1, 2, 1, 2, 3], 1) # 3 ``` +### countVowels + +Retuns `number` of vowels in provided `string`. + +Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a string. + +```python +import re + + +def countVowels(str): + return len(len(re.findall(r'[aeiou]', 'bcedfidsnoxluAEIO', re.IGNORECASE))) + +``` + +``` python +countVowels('foobar') # 3 +countVowels('gym') # 0 +``` ### gcd Calculates the greatest common divisor between two or more numbers/lists. diff --git a/snippets/countVowels.md b/snippets/countVowels.md new file mode 100644 index 000000000..2f3450f1d --- /dev/null +++ b/snippets/countVowels.md @@ -0,0 +1,19 @@ +### countVowels + +Retuns `number` of vowels in provided `string`. + +Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a string. + +```python +import re + + +def countVowels(str): + return len(len(re.findall(r'[aeiou]', 'bcedfidsnoxluAEIO', re.IGNORECASE))) + +``` + +``` python +countVowels('foobar') # 3 +countVowels('gym') # 0 +``` \ No newline at end of file