с использованием filter
- хороший вариант.
my_list = [(3, 3, 3, 3, 3), (1, 2, 3, 3, 3, 3), (2, 2, 2, 3, 3, 3), (1, 1, 1, 3, 3, 3, 3), (1, 1, 2, 2, 3, 3, 3), (1, 2, 2, 2, 2, 3, 3), (2, 2, 2, 2, 2, 2, 3), (1, 1, 1, 1, 2, 3, 3, 3), (1, 1, 1, 2, 2, 2, 3, 3), (1, 1, 2, 2, 2, 2, 2, 3), (1, 2, 2, 2, 2, 2, 2, 2), (1, 1, 1, 1, 1, 1, 3, 3, 3), (1, 1, 1, 1, 1, 2, 2, 3, 3), (1, 1, 1, 1, 2, 2, 2, 2, 3), (1, 1, 1, 2, 2, 2, 2, 2, 2), (1, 1, 1, 1, 1, 1, 1, 2, 3, 3), (1, 1, 1, 1, 1, 1, 2, 2, 2, 3), (1, 1, 1, 1, 1, 2, 2, 2, 2, 2), (1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), (1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3), (1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2), (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3), (1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2), (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3), (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2), (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2), (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)]
sol =list(filter (lambda x:x.count(1)<5, my_list))
print(sol)
output
[(3, 3, 3, 3, 3),
(1, 2, 3, 3, 3, 3),
(2, 2, 2, 3, 3, 3),
(1, 1, 1, 3, 3, 3, 3),
(1, 1, 2, 2, 3, 3, 3),
(1, 2, 2, 2, 2, 3, 3),
(2, 2, 2, 2, 2, 2, 3),
(1, 1, 1, 1, 2, 3, 3, 3),
(1, 1, 1, 2, 2, 2, 3, 3),
(1, 1, 2, 2, 2, 2, 2, 3),
(1, 2, 2, 2, 2, 2, 2, 2),
(1, 1, 1, 1, 2, 2, 2, 2, 3),
(1, 1, 1, 2, 2, 2, 2, 2, 2)]