fork download
  1. import re
  2.  
  3. pattern = r"(?=(1[01]{3}0))"
  4. s = "011010010111001101101111011011010110110101110011010000110010010111000100100110110101101111011011110111011001101100011011010111011001101000011001001101100011100010010110110011111011001110001001011011"
  5.  
  6. cnt = dict()
  7. for i in re.findall(pattern, s):
  8. # get the value by key, or return 0 if the key does not exist
  9. cnt[i] = cnt.get(i, 0) + 1
  10.  
  11. print(cnt)
Success #stdin #stdout 0.03s 9624KB
stdin
Standard input is empty
stdout
{'11010': 7, '10100': 3, '10010': 7, '11100': 5, '10110': 17, '11110': 4, '10000': 2, '11000': 5}