[fix] issue #20
This commit is contained in:
@ -4,16 +4,11 @@
|
|||||||
|
|
||||||
Counts the occurrences of a value in an list.
|
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.
|
Uses the list comprehension to increment a counter each time you encounter the specific value inside the list.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from functools import reduce
|
def count_occurrences(lst, val):
|
||||||
|
return len([x for x in lst if x == val and type(x) == type(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)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|||||||
Reference in New Issue
Block a user