Popular hashtags

Write code · Medium · §6.1 Putting things in order

tags holds the hashtags used in posts. If a hashtag was used several times, it appears in tags that many times.

Complete the function solution, which returns a list of the k most used hashtags, from most used to least used. Hashtags used the same number of times are listed in ascending order, the way sorted() sorts strings.

If there are fewer than k different hashtags, include all of them, following the same rules.

Function

solution(tags, k)

Constraints

Examples

tagskresult
['ai', 'cat', 'ai', 'food', 'cat', 'ai']2['ai', 'cat']
['dog', 'dog', 'music', 'travel', 'travel', 'travel']3['travel', 'dog', 'music']

Starter code

def solution(tags, k):
    answer = []
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.