fork download
  1. import re
  2.  
  3. pattern = r"(?=(1[01]{2}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.04s 9600KB
stdin
Standard input is empty
stdout
{'1010': 7, '1110': 11, '1100': 13, '1000': 7}