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 code in question you're asking about comes from my answer given [here](https://stackoverflow.com/questions/19258605/difference-between-multiple-elements-in-list-with-same-string-python-2-7/). It was intended to solve the problem of comparing multiple bit arrays - i.e. collections of `1` and `0`.

`any` and `all` are useful when you can rely on the "truthiness" of values - i.e. their value in a boolean context. 1 is `True` and 0 is `False`, a convenience which that answer leveraged. 5 happens to also be `True`, so when you mix that into your possible inputs... well. Doesn't work.

You could instead do something like this:

```
[len(set(x)) > 1 for x in zip(*d['Drd2'])]

```

It lacks the aesthetics of the previous answer (I *really* liked the look of `any(x) and not all(x)`), but it gets the job done.
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 

```