This is the fourth article of my attempts to follow Stephen Grider's Udemy course in three different languages.
First I quote todays's question:
...
For further actions, you may consider blocking this person and/or reporting abuse
Python could do it even better.
I would have done this that way and using the built in 'max' method for the Counter object
To explain a little bit to non Python dev:
if
s
is a valid chain, I build a Counter object with it, get the list of the n (letter, count) elements, getting the first one and returning only the letter.Step by step:
Wow, this looked enigmatic at first, but I understood how it works. Thank you!
Thank you for the comment!
I learned quite a lot from this code. I really appreciate it. Below is just for my understanding:
Actually we can make it more concise with the way I used above for the
max
function:I like how we can write python like psuedocode with few lines.
count element in an element
=> Counter(s)
Though it can be hard to understand and remember all the shortcuts.