Just a comment on the common interview question Mosh gave. In his solution, he used a dictionary and went through a loop and incremented each char by 1 when found. Then he reverse sorted and popped the first one.
I have a few problems with that method. What if there are two chars or more that are used at the same frequency, this misses it. What if the space or other non-letter character is the most used, would you want that reported, because they said the most used letter.
This is how I solved it:
from itertools import count
sentence = "This is a really common interview question"
x = 0
most_used = []
for y in sentence:
if (not y.isalpha()):
continue # Ignore all non letter chars
if (sentence.count(y) > x):
x = sentence.count(y)
most_used.clear()
most_used.append(y)
elif (sentence.count(y) == x) and (y not in most_used):
most_used.append(y)
if len(most_used) == 1:
print(
f"The letter that is most used: '{most_used[0]}'. It was used {x} times")
else:
print(f"The letters most used are: {most_used}. They are used {x} times")