Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12
Aleksei Radchenkov , you are showing a really nice code to help someone solving a task. we all appreciate this very much!  (this is my personal statement - but it is not to criticize someone !!) but there is an issue by giving a ready solution, when the op has not done and shown his attempt first. as a part of the community i believe that learning by doing is more helpful, than just using a shared solution. we should act more as a mentor.  it is a very successful way when we are giving hints and help, so that the op is able to solve his task by himself. it would be great if you are going to help us to keep sololearn what it is: ▪︎a unique place to learn (we are a "self" learning platform!) ▪︎an absolutely great community that is willing to help other people  ▪︎a great resource of people which has an unbelievable knowledge in coding and a long lasting experience ▪︎a place to meet people and to discuss with them all the possible points of view thanks for your understanding
27th Sep 2021, 9:45 AM
Lothar
Lothar - avatar
+ 5
Manoj , there is very simple way to solve it, just one line of code. but we are still waiting to see your attempt first...
27th Sep 2021, 9:44 AM
Lothar
Lothar - avatar
+ 2
Lothar Yeah of course you are correct bro))
27th Sep 2021, 9:54 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
this is the code i mentioned: inp = input().split() # "w1 w2 w3 w1 w4 w2 w3 w1 w1" => "w1", "w2 w3 w1 w4 w2 w3 w1 w1 w2 w2 w1" => "w2" print(max(inp, key=inp.count))
28th Sep 2021, 10:39 AM
Lothar
Lothar - avatar
27th Sep 2021, 4:58 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Manoj, show us your attempt first. Don't ask us to do it for you.
27th Sep 2021, 5:16 AM
David Akhihiero
David Akhihiero - avatar
+ 1
Nested for loop is a workaround but it's never the only solution. It would have a huge impact on performance as the size of the list increases. I'd suggest looping through the list once and storing each item in a dictionary. Furthermore, it's easier to check what exactly has appeared the most and for those cases when there are 2 and more items of the same amount.
27th Sep 2021, 7:30 AM
Tim
Tim - avatar
+ 1
Nick, yeah bro I know;) I did it cuz it's the quickest way to do it.... Obviously writing it in a dictionary is way better for performance... I just wanted to make it as quick as possible))) There are a thousand better ways to do it.....
27th Sep 2021, 8:00 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Sorry guys I don't know about this platform, next time onwards definitely I'll post qus with my attempt
27th Sep 2021, 11:24 AM
Manoj Kumar T
Manoj Kumar T - avatar
+ 1
Manoj n=str(input()).split() max="" for i in n: if n.count(i)>n.count(max): max=i print(max)
27th Sep 2021, 6:24 PM
Hemmat
Hemmat - avatar
+ 1
MH.Hemmat , it is still nested loops, so performance will be awful for big strings. As Nick said adding elements to the dictionary first is way better.
27th Sep 2021, 10:25 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Aleksei Radchenkov Manoj Nick ''' > without use max() method of dictionary. > Find the largest items that have the most repeat. ''' text = str(input()).split() dict = {} max=1 for n in text: dict[n]=text.count(n) if dict.get(n)>max: max=dict[n] for n in dict: if dict[n]==max: print(n,end=' ')
28th Sep 2021, 7:43 AM
Hemmat
Hemmat - avatar
0
Python has built-in function for this problem: from collections import Counter a= input().split() count = Counter(a) m = max(count.values()) print(list(count.keys())[list(count.values()).index(m)])
28th Sep 2021, 5:08 PM
Gajendra Sonare
Gajendra Sonare - avatar
- 2
some things that ur saying arnt makeing sense to me because im a begginer
29th Sep 2021, 12:37 AM
Cookie Fans club
Cookie Fans club - avatar