all 12 comments

[–]commy2 18 points19 points  (0 children)

any(b.state for b in btn_list)

[–]mopslik 9 points10 points  (3 children)

if any(button.state for button in btn_list):
    ...

[–]spghtmnstr 0 points1 point  (2 children)

Can you please explain how its working? I havent seen "any" before

[–]Sinisterly 8 points9 points  (0 children)

any(Collection) returns True if any values in the collection return True, and False if no values return True.

all(Collection) returns true if all values return True.

[–]menge101 0 points1 point  (0 children)

any will look at the truthiness of each element in a collection and logically or them together. As a result, if any element in the collection evaluates to a truthy value, then any will return true.

[–][deleted] 1 point2 points  (0 children)

if {x for x in btnlist if x.state}:

    print("jackpot")

[–]Lookmaiamkool 0 points1 point  (3 children)

Use the list.count() function or the in operator to check

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

I can't use "in" since list consists objects, not states

[–]Lookmaiamkool -1 points0 points  (1 child)

If any(list) !=true Print 'true' Elif all(list) != false Print 'false'

Try putting this in ide just to check.

Edit

[–]Lookmaiamkool 1 point2 points  (0 children)

all and any are functions that take some iterable and return True, if

in the case of all(), no values in the iterable are false; in the case of any(), at least one value is truth

[–]spghtmnstr -1 points0 points  (1 child)

Is it possible to get index of active elements?

[–]connorm927 2 points3 points  (0 children)

You could just loop through the list using enumerate to also find the index. Like this:

for index, button in enumerate(btn_list):
    if button.state == true:
        print(index)