From 0122a09178cece2d675a1022e79a21110dc0da6c Mon Sep 17 00:00:00 2001 From: huybery <707146450@qq.com> Date: Mon, 26 Feb 2018 10:00:18 +0800 Subject: [PATCH 1/2] [fix] issue #20 --- snippets/count_occurences.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/snippets/count_occurences.md b/snippets/count_occurences.md index ceaa821fe..354230cfb 100644 --- a/snippets/count_occurences.md +++ b/snippets/count_occurences.md @@ -4,18 +4,13 @@ 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 -from functools import reduce - - -def count_occurences(arr, val): - return reduce( - (lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0), - arr) +def count_occurrences(lst, val): + return len([x for x in lst if x == val and type(x) == type(val)]) ``` ```python count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3 -``` \ No newline at end of file +``` From 360f4d05ed5cbcc9e40e33655c8fc0cff74b7f0e Mon Sep 17 00:00:00 2001 From: huybery <707146450@qq.com> Date: Mon, 26 Feb 2018 10:02:43 +0800 Subject: [PATCH 2/2] [update] contributor_database --- contributor_database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributor_database b/contributor_database index 009d86b35..d84b059c2 100644 --- a/contributor_database +++ b/contributor_database @@ -1,7 +1,7 @@ average:[Rohit Tanwar](@kriadmin),[Hui Binyuan](@huybery) chunk:[Rohit Tanwar](@kriadmin) compact:[Rohit Tanwar](@kriadmin) -count_occurences:[Rohit Tanwar](@kriadmin) +count_occurences:[Rohit Tanwar](@kriadmin), [Hui Binyuan](@huybery) count_vowels:[Rohit Tanwar](@kriadmin) deep_flatten:[Rohit Tanwar](@kriadmin),[Meet Zaveri](@meetzaveri) difference:[Rohit Tanwar](@kriadmin)