From 10422852cc5e61c0afda6dd76c473292a138e358 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 22 Sep 2019 15:31:11 +0300 Subject: [PATCH] Update some.md --- snippets/some.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/snippets/some.md b/snippets/some.md index 3e4769a72..6d6e16ef1 100644 --- a/snippets/some.md +++ b/snippets/some.md @@ -5,15 +5,11 @@ tags: list,function,intermediate Returns `True` if the provided function returns `True` for at least one element in the list, `False` otherwise. -Iterate over the elements of the list to test if every element in the list returns `True` based on `fn`. -Omit the seconds argument, `fn`, to check if all elements are `True`. +Use `any()` in combination with `map()` and `fn` to check if `fn` returns `True` for any element in the list. ```py -def some(lst, fn=lambda x: not not x): - for el in lst: - if fn(el): - return True - return False +def some(lst, fn=lambda x: x): + return any(map(fn, lst)) ``` ```py