From 9754a4c2d4abde97e9150e66297a85199be8c219 Mon Sep 17 00:00:00 2001 From: Arijit Layek Date: Sat, 30 Apr 2016 12:47:19 +0000 Subject: [PATCH 1/3] Add Python all --- python-all.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 python-all.md diff --git a/python-all.md b/python-all.md new file mode 100644 index 0000000000..b81f311e4b --- /dev/null +++ b/python-all.md @@ -0,0 +1,40 @@ +# Python all(iterable) + +`all()` is a built in function in Python 3, to check if all items of an [_iterable_](https://docs.python.org/3/glossary.html#term-iterable) is `True`. It takes one argument, `iterable`. + +## Argument +### iterable + +The `iterable` argument is the collection whose all entries are to be checked. It can typically be a `list`, `str`, `dict`, `tuple` etc. + +## Return Value +The return value would be a boolean. If and only if **all** entries of iterable are `True`, it returns `True`. This function essentially performs a Boolean `AND` operation over all elements. + +If even one of them is not `True`, it would return `False`. + +The `all()` operation is equivalent to (not internally implemented exactly like this) + +```python +def all(iterable): + for element in iterable: + if not element: + return False + return True +``` + +## Code Sample + +```python +print(all([6, 7])) #=> True +print(all([6, 7, None])) #=> False Because this has None +print(all([0, 6, 7])) #=> False Because this has zero +print(all([9, 8, [1, 2]])) #=> True +print(all([9, 8, []])) #=> False Because it has [] +print(all([9, 8, [1, 2, []]])) #=> True +print(all([9, 8, {}])) #=> False Because it has {} +print(all([9, 8, {'engine': 'Gcloud'}])) #=> True + +``` +:rocket: [REPL It!](https://repl.it/CL9U/0) + +[Documentation](https://docs.python.org/3/library/functions.html#all) From 1f450724c0a8727785614fd694fe34883b8544cf Mon Sep 17 00:00:00 2001 From: Arijit Layek Date: Sat, 30 Apr 2016 14:07:31 +0000 Subject: [PATCH 2/3] Fix built in --- python-all.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-all.md b/python-all.md index b81f311e4b..a0ea885c1a 100644 --- a/python-all.md +++ b/python-all.md @@ -1,6 +1,6 @@ # Python all(iterable) -`all()` is a built in function in Python 3, to check if all items of an [_iterable_](https://docs.python.org/3/glossary.html#term-iterable) is `True`. It takes one argument, `iterable`. +`all()` is a built-in function in Python 3, to check if all items of an [_iterable_](https://docs.python.org/3/glossary.html#term-iterable) is `True`. It takes one argument, `iterable`. ## Argument ### iterable From c66ebcc9d1e413c2e661b295b159c9a82cc6e6de Mon Sep 17 00:00:00 2001 From: Arijit Layek Date: Sat, 30 Apr 2016 14:48:51 +0000 Subject: [PATCH 3/3] Add some more fixes --- python-all.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-all.md b/python-all.md index a0ea885c1a..f8cfb1c61e 100644 --- a/python-all.md +++ b/python-all.md @@ -1,4 +1,4 @@ -# Python all(iterable) +# Python `all(iterable)` `all()` is a built-in function in Python 3, to check if all items of an [_iterable_](https://docs.python.org/3/glossary.html#term-iterable) is `True`. It takes one argument, `iterable`. @@ -37,4 +37,4 @@ print(all([9, 8, {'engine': 'Gcloud'}])) #=> True ``` :rocket: [REPL It!](https://repl.it/CL9U/0) -[Documentation](https://docs.python.org/3/library/functions.html#all) +[Official Docs](https://docs.python.org/3/library/functions.html#all)