change_case

This commit is contained in:
Rohit Tanwar
2018-01-16 17:43:47 +05:30
parent aede69f162
commit f3fd73f70e
3 changed files with 12 additions and 11 deletions

View File

@ -1,11 +1,11 @@
### countOccurences
### count_occurences
Counts the occurrences of a value in an list.
Uses the `reduce` functin from built-in module `functools` to increment a counter each time you encounter the specific value inside the list.
```python
def countOccurences(arr, val):
def count_occurences(arr, val):
return reduce(
(lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0),
arr)
@ -13,5 +13,5 @@ def countOccurences(arr, val):
```
```python
countOccurrences([1, 1, 2, 1, 2, 3], 1) # 3
count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3
```

View File

@ -1,4 +1,4 @@
### countVowels
### count_vowels
Retuns `number` of vowels in provided `string`.
@ -8,12 +8,12 @@ Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a st
import re
def countVowels(str):
def count_vowels(str):
return len(len(re.findall(r'[aeiou]', str, re.IGNORECASE)))
```
``` python
countVowels('foobar') # 3
countVowels('gym') # 0
count_vowels('foobar') # 3
count_vowels('gym') # 0
```