title: Optimize to get the most and least occurrences of pairs of from the list
body: <p>I have 10K list of 20 values like below in a dat file -</p>
  <ol>
  <li>Medical, 24673, 23578, Orange, USA, Green, 25980, Canada, IT, 2M376, Engineering, 50925, 39421, Apple, India, Red, 77789, Mexico, FIN, 3R376</li>
  <li>24673, 23578, HongKong, Green, Management, 77789, Canada, HR, HL238, Engineering, 34009, 22173, Netflix, India, Jio, 77789, Mexico, OPS, 3R376, Orange</li>
  </ol>
  <p>I ran below program to find the top 3 most occurred combination of 5 values like suppose [Medical, 24673, 23578, India, Mexico] - Occurred 1000 times. But program is keep running for very long time - more then 10 hours and then I stopped it. Can you please provide any optimize way to run the same.</p>
  <pre><code>from itertools import combinations
  from collections import Counter
  import ast
  
  def most_frequent_combs(fn):
      counter1 = Counter()
      for ln in open(fn):
          unique_tokens = sorted(set(ast.literal_eval(ln)))
          combos = combinations(unique_tokens, 5)
          counter1 += Counter(combos)
      return counter1
  
  fn = '/data/unix_framework/landing/summit/finalcollection.dat'
  p = most_frequent_combs(fn)
  print(p.most_common(3))
  print(p.most_common()[-3])
  </code></pre>