Question: I'm trying to understand how the `any()` and `all()` Python built-in functions work.

I'm trying to compare the tuples so that if any value is different then it will return `True` and if they are all the same it will return `False`. How are they working in this case to return [False, False, False]?

`d` is a `defaultdict(list)`.

```
print d['Drd2']
# [[1, 5, 0], [1, 6, 0]]
print list(zip(*d['Drd2']))
# [(1, 1), (5, 6), (0, 0)]
print [any(x) and not all(x) for x in zip(*d['Drd2'])]
# [False, False, False]

```

To my knowledge, this should output

```
# [False, True, False]

```

since (1,1) are the same, (5,6) are different, and (0,0) are the same.

**Why is it evaluating to False for all tuples?**

---

See [Pythonic way of checking if a condition holds for any element of a list](https://stackoverflow.com/questions/1342601) for practical usage of `any`.

Answer: 
I know this is old, but I thought it might be helpful to show what these functions look like in code. This really illustrates the logic, better than text or a table IMO. In reality they are implemented in C rather than pure Python, but these are equivalent.

```
def any(iterable):
    for item in iterable:
        if item:
            return True
    return False

def all(iterable):
    for item in iterable:
        if not item:
            return False
    return True

```

In particular, you can see that the result for empty iterables is just the natural result, not a special case. You can also see the short-circuiting behaviour; it would actually be more work for there *not* to be short-circuiting.

When Guido van Rossum (the creator of Python) [first proposed adding `any()` and `all()`](https://www.artima.com/weblogs/viewpost.jsp?thread=98196), he explained them by just posting exactly the above snippets of code.
The all() function is used to check every member of a collection as being truthy or not. For example, the all() function can be used to more succinctly conditionalize statements of the following form:

```
if all entre's are vegan this is a vegan restaurant

```

In code:

```
restaurant_is_vegan = all(x is vegan for x in menu)

```

If every item (x) on the menu (iterator) evaluates to True for the conditional (is vegan; x == vegan) the all statement will evaluate to True.

More examples here: <https://www.alpharithms.com/python-all-function-223809/>