This refactor separates the counting logic from the main function, making the code more maintainable and easier to understand. Additionally, the function uses a generator expression instead of creating an intermediate list, which can save memory when dealing with large lists.
def count_true_bools(lst): return sum(1 for item in lst if isinstance(item, bool) and item) def solution(lst): return count_true_bools(lst) >= 2
solution = lambda x: sum(b for b in x if isinstance(b, bool)) >= 2- def count_true_bools(lst):
- return sum(1 for item in lst if isinstance(item, bool) and item)
- def solution(lst):
- return count_true_bools(lst) >= 2