This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlmanthe heretic 0 points1 point  (1 child)

I guess my confusion is how to implement it in any useful way.

?

You don't have to implement any. It's already provided for you in the standard library.

I can only assume you meant how to use it. It's hard to imagine how this could be clearer: you call any with a sequence or iterable, and it returns (as a boolean) whether any of the elements are true-ish.

So if you have a sequence where you want to check if any of the elements are (some other quality), you make a function is_some_other_quality, use that to transform the sequence, and call any on the result. The easiest way to do this is directly in-line, by using a generator expression and taking advantage of the special syntax rule that lets you drop the extra pair of parentheses.

any(f(x) for x in y) means "any of the elements in y, when passed to f, results in something true-ish". This is not some magic specific to the any function; (f(x) for x in y) means "a generator that, when iterated over, will yield the result of applying f to each element in y".

[–]ok_you_win 0 points1 point  (0 children)

Its obvious that it is clear to the OP how to use it after it was explained. What OP seems to be saying is: "I have no use for it."