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: 
The concept is simple: 

```
M =[(1, 1), (5, 6), (0, 0)]

1) print([any(x) for x in M])
[True, True, False] #only the last tuple does not have any true element

2) print([all(x) for x in M])
[True, True, False] #all elements of the last tuple are not true

3) print([not all(x) for x in M])
[False, False, True] #NOT operator applied to 2)

4) print([any(x)  and not all(x) for x in M])
[False, False, False] #AND operator applied to 1) and 3)
# if we had M =[(1, 1), (5, 6), (1, 0)], we could get [False, False, True]  in 4)
# because the last tuple satisfies both conditions: any of its elements is TRUE 
#and not all elements are TRUE 

```
I think there is something strange in the logic how `any()` evaluates the conditions. The Python documentation (as also reported here) says that at least one condition should evaluate to True, but it does not tell that ALL conditions are evaluated!

For instance, I was struggling with the below code, because I was thinking that `any()` does not evaluate all conditions:

```
def compare(list_a, list_b):
    if any([list_a is None, list_b is None, len(list_a) == 0, len(list_b) == 0]):
        return 'no comparison'
    else:
        return 'need comparison'

print(compare(list_a=None, list_b=[1, 2, 3]))

```

The above code raises an exception because any still evaluates `len(list_a) == 0`.
In this case, the logic used by `any()` is VERY dangerous, because I would have expected that only the first condition is evaluated.

Below code must be used in this case:

```
def compare(list_a, list_b):
    if list_a is None or list_b is None or len(list_a) == 0 or len(list_b) == 0:
        return 'no comparison'
    else:
        return 'need comparison'

print(compare(list_a=None, list_b=[1, 2, 3]))

```