I have a list of tuples as follows:
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)]
I need to extract tuples in which number 1
is repeated less than 5 times. I have read here, here and some other posts, and based on these I have written the following:
results = []
for i in range(len(my_list)):
a = [elem for elem in my_list if my_list[i].count(1) < 5]
results.append(a)
This is not working giving me another list of lists. Could anyone give me a hint what I am doing wrong here? Thanks!