May-22-2018, 07:06 PM
Hi, I'm trying to solve this exercise: https://open.kattis.com/problems/conversationlog .
I've managed to get a list with the words sorted by the number of occurrence but I'm still having troubles because I don't know what the exercise means with "most used words" and I don't understand it from the example.
This is what I've done so far:
I've managed to get a list with the words sorted by the number of occurrence but I'm still having troubles because I don't know what the exercise means with "most used words" and I don't understand it from the example.
This is what I've done so far:
#!/usr/bin/python3 import collections m = int(input()) chat_list = [input().split() for _ in range(m)] [i.pop(0) for i in chat_list] #remove the first word, which is the user name, from every list words = [i for sublist in chat_list for i in sublist] #create a list with every words counter = collections.Counter(words) a = counter.most_common() print(a)