What is the output of the following? “`python from collections import Counter c = Counter(‘aabbccca’) print(c.most_common(2)) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python from collections import Counter c = Counter(‘aabbccca’) print(c.most_common(2)) “`

Key points

  • Counter.most_common() returns a list of the n most common elements and their counts
  • The elements are returned in descending order of their counts
  • If there are ties in counts, the order of elements with the same count is unspecified

Ready to go further?

Related questions