fork download
  1. import collections
  2.  
  3.  
  4. text = 'abba com mother bill mother com abba dog abba mother com'
  5. array = text.split()
  6. counter = collections.Counter()
  7.  
  8. for n in range(len(array) - 2):
  9. three = ' '.join(sorted(array[n:n + 3]))
  10. counter[three] += 1
  11.  
  12. print(counter.most_common(1))
  13.  
Success #stdin #stdout 0.02s 9136KB
stdin
Standard input is empty
stdout
[('abba com mother', 3)]