Return the k most frequent characters of s as a list of [character, count] pairs, most frequent first. When two characters have the same count, the one that comes first alphabetically goes first.
If s has fewer than k different characters, return all of them.
Example 1
Input:
top_characters('abracadabra', 2)
Output:
[['a', 5], ['b', 2]]
a appears 5 times and b and r twice each; b is before r.
Example 2
Input:
top_characters('zzyyx', 5)
Output:
[['y', 2], ['z', 2], ['x', 1]]
Only three different characters exist, so all three are returned. y and z tie, so y is first.
0 <= len(s) <= 3 * 10**50 <= k <= 100s contains only lower-case letters.No results yet
Run your code to check it against the examples, or submit to run every test.