fork download
  1. string = 'abba com mother bill mother com abba dog abba mother com'
  2. words = string.split()
  3. res = {}
  4. for n in range(len(words)-2):
  5. comb = ' '.join(sorted(words[n:n+3]))
  6. res[comb] = res.get(comb, 0) + 1
  7. print(res)
Success #stdin #stdout 0.02s 9120KB
stdin
Standard input is empty
stdout
{'abba com mother': 3, 'bill com mother': 2, 'bill mother mother': 1, 'abba com dog': 1, 'abba abba dog': 1, 'abba dog mother': 1}