I wrote this program:
from collections import defaultdict
num = int(input())
mylist = defaultdict(list)
#Horror = Romance = Comedy = History = Adventure = Action = []
for i in list(range(num)):
str = input()
#lst.append(str)
word = str.split()
for i in word[1:]:
if i == "Horror":
mylist["Horror"].append(word[0])
if i == "Romance":
mylist["Romance"].append(word[0])
if i == "Comedy":
mylist["Comedy"].append(word[0])
if i == "History":
mylist["History"].append(word[0])
if i == "Adventure":
mylist["Adventure"].append(word[0])
if i == "Action":
mylist["Action"].append(word[0])
for i in ["Action" , "Comedy" , "History" , "Horror" , "Romance" , "Adventure"]:
print(f"{i} : {len(mylist[i])}")
I want this program to publish the most interesting genres in order.
example: for this input:
4
hossein Horror Romance Comedy
mohsen Horror Action Comedy
mina Adventure Action History
Farhad Romance Horror Action
i want to get this output:
Action : 3
Horror : 3
Comedy : 2
Romance : 2
Adventure : 1
History : 1
Please help me.
...............................................................................................................................................................................