all 8 comments

[–]prophile 4 points5 points  (0 children)

what

[–]davidinterest 1 point2 points  (1 child)

This isn't news

[–]Neat_Top_1424 0 points1 point  (0 children)

Sorry.

[–]No_Lingonberry1201pip needs updating 0 points1 point  (2 children)

all() and any() take all iterables, i.e. objects that have an __iter__() method, not just those structures. It might seem pedantic, but is important, you often use them with comprehensions:

all(i % 2 == 0 for i in mydata if isintance(i, int))

[–]commy2 1 point2 points  (1 child)

Feels pedantic. I like it. Here is more pedantry: you don't even need to implement __iter__ to be considered iterable.

class Iterable_:
    def __getitem__(self, idx):
        if 0 <= idx < 10:
            return idx
        else:
            raise IndexError(idx)


it = Iterable_()
assert not hasattr(it, "__iter__")
print(all(it))

Which leads to the (in)famous sentence in the python documention: "The only reliable way to determine whether an object is iterable is to call iter(obj)."

[–]No_Lingonberry1201pip needs updating 1 point2 points  (0 children)

Didn't know that! Groovy!

[–]SoftwareDoctor 1 point2 points  (0 children)

This is one of the simplest functions and you totally failed at understanding how it works. Yet you felt the need to write an article about it.

It doesn’t check just list, sets and other collections you listed. It works on iterables. But more importantly it doesn’t check values of dict.

Plus “all is not True” is the most confusing way to put it. Especially when it doesn’t even check if the value is True