I am having a text file in which some binary numbers are there. I want to count number of occurrence of some digits/characters using pattern, and I want to sort it in descending order (till this point code working fine. but I want result should show only more than 7 characters. it means i can change in my selection pattern = r"(0+1+0+1+0+1+)" {<7}
import re
from collections import Counter
pattern = r"0+1+0+1+0+1+"
test_str = '0101010110110110110110110101010111011101110111101111010101111010111010101111011010101011011011011011011011'
cnt = Counter(re.findall(pattern, test_str))
print(cnt.most_common())
# result [('011011011', 2), ('010101', 1), ('0111011101111', 1), ('010111101', 1), ('0111101101', 1)]
result should be display only more than 8 character it no supposed to show ('010101', 1)