Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Counter(arr).items()
returns a list of[(key1, value1), (key2, value2), ...]
where the keys are the distinct numbers inarr
and the values are the occurrences of that key inarr
. You can pass this into themax
function with a customkey
to retrieve the max value. The key takes in a(key, value)
instance and compares it against other elements by first comparingx[1]
thenx[0]
wherex[1]
is the occurrence of that number andx[0]
is the number as stated before. You need to apply[0]
to the outputted(key,value)
of the max function to obtain the distinct number.I discovered this too, good to know
your post helped me discover decorators, thanks
can you please explain your solution, thanks
Wasn't familar with the formatting So looked for it in the stackoverflow and realised your wonderfull simple solution..
one of the main reason that keeps me in codewar is to see codes like this.
I tried to do something similar,
normally efficiency. But here, it's done in a pretty stupid way, which makes this solution even slower than the O(n²) solution without the set... XD
=> See the fork.
This comment is hidden because it contains spoiler information about the solution
clever for using the slicing at the beginning
This is really similar to my idea. but I need to learn more to have this kind of reflexes.
good job
This comment is hidden because it contains spoiler information about the solution
Clever using list.index, didn't thought of that