List comprehension with boolean (Python)

Question:

How to present this code as a list comprehension:

def all_targets_hit(attempts: list) -> bool:

    for ls in range(len(attempts)):
        if not any(attempts[ls]):
            return False
    return True

attempts =([
            [True, False, False],
            [False, False, True],
            [False, False, False, False],
        ]) 

#Expected: False

Asked By: avkpol

||

Answers:

You could combine all with any:

def all_targets_hit(attempts: list) -> bool:
    return all([any(sublist) for sublist in attempts])

attempts =([
            [True, False, False],
            [False, False, True],
            [False, False, False, False],
        ]) 

all_targets_hit(attempts)
Answered By: Maurice Meyer