Hi Programmers,
I hope you are doing well, so in todays session we are again back with a list question of python. So let's understand the problem first then we will move further.
input = ["i am a good programmer", "i am also a good person", "Passing with good marks is my hobby"]
output = good : 3 times
new_lst = []
new_dict = {}
for sentence in input_data:
new_lst += sentence.split()
for word in new_lst:
if word in new_dict:
new_dict[word] += 1
else:
new_dict[word] = 1
word_name = max(new_dict, key=new_dict.get)
word_count = new_dict[word_name]
print(word_name, word_count)
I hope you have got the idea how you can solve this problem. There might be more solutions for this problem if I will get any idea, i will surely update this post.
Thanks for your valuable time. You can like my post
you can,
Top comments (0)