Code:
def mostFrequent(word,frequency,n): my_list = zip(word,frequency) #combine the two lists my_list.sort(key=lambda x:x[1],reverse=True) #sort by freq words,freqs = zip(*my_list[:n]) #take the top n entries and split back to seperate lists return words, freqs #return our most