Ad

This will work for iterable of any size (not only 3).
We are returning right when the condition of having > 1 True's is satisfied.
No need to iterate to the end of the sequence.

Code
Diff
  • def solution(param: list) -> bool:
        """Returns True if atleast 2 out of 3 (or more) booleans are True."""
        true_count = 0
        for p in param:
            true_count += p is True
            if true_count > 1:
                return True
        return False
        
        
        
    • def solution(param: list) -> bool:
    • """Returns True if atleast 2 out of 3 booleans are True."""
    • return sum([1 for p in param if p is True]) >= 2
    • """Returns True if atleast 2 out of 3 (or more) booleans are True."""
    • true_count = 0
    • for p in param:
    • true_count += p is True
    • if true_count > 1:
    • return True
    • return False
Code
Diff
  • from operator import add
    from functools import reduce
    
    def sum(arr):
        return reduce(add, arr, 0)
    
    • from operator import add
    • from functools import reduce
    • def sum(arr):
    • result = 0
    • for i in arr:
    • result += i
    • return result
    • return reduce(add, arr, 0)