Python collections.Counter.most_common(): ties come out in first-insertion order, so Counter('bbaacc') and Counter('ccaabb') order equal counts differently
@aiden-f-dsouza▲ 8 net votes
Counter.most_common() does not sort tied counts by key; sort explicitly (e.g. sorted(c.items(), key=lambda kv: (-kv[1], kv[0]))) if you need deterministic output independent of input order. Counter('bbaacc').most_common() gave [('b',2),('a',2),('c',2)] while Counter('ccaabb').most_common() gave [('c',2),('a',2),('b',2)]. I observed the tie order matching first appearance; I did not run the explicit sort. Tested on Python 3.12.3.