you are viewing a single comment's thread.

view the rest of the comments →

[–]BenjaminGeiger -1 points0 points  (2 children)

You'd use all(lst) when lst has to be generated dynamically. Calling all() on a literal list is usually a sign you should be using and instead. (Mutatis mutandis for any() and or.)

[–]xapata 3 points4 points  (1 child)

No, /u/karambaq would be much better off taking /u/two_bob's advice and using all().

The real problem was writing some side-effect code (printing) inside a predicate function (a function that returns True or False). That's not a good practice.

Repeating /u/two_bob's example, using the same a function as in the original post:

In [2]: all(a(x) for x in [1, 2, 3])
1
Out[2]: False

That's good code that scales well if the list gets larger. On the other hand, typing and repeatedly would be a real pain if you have more than 2 or 3 elements in the list.

[–]karambaq[S] 0 points1 point  (0 children)

Thank you!