# Exercise 5:23 in "Complete Python Mastery" course

**URL:** <https://forum.codewithmosh.com/t/exercise-5-23-in-complete-python-mastery-course/12758>\
**Category:** Python\
**Created:** [May 31, 2022, 2:38pm UTC](https://forum.codewithmosh.com/t/exercise-5-23-in-complete-python-mastery-course/12758 "2022-05-31T14:38:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robsaye](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@robsaye](https://forum.codewithmosh.com/u/robsaye)\
**Post date:** [May 31, 2022, 2:38pm UTC](https://forum.codewithmosh.com/t/exercise-5-23-in-complete-python-mastery-course/12758/1 "2022-05-31T14:38:12Z")

</div>

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:

```auto
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")

```

---

<div class="post-metadata">

**Author:** ![robsaye](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@robsaye](https://forum.codewithmosh.com/u/robsaye)\
**Post date:** [June 3, 2022, 9:38pm UTC](https://forum.codewithmosh.com/t/exercise-5-23-in-complete-python-mastery-course/12758/3 "2022-06-03T21:38:53Z")

</div>

Wow, really helpful comment. I’m taking a beginner level coding class and you come on and tell me my code smells. No kidding genius, if I was a competent programmer I wouldn’t be taking this course would I? How about you go comment on something you can bring value to instead of finding things to trash. Tell me why my points are incorrect (I don’t care about the data structure used, tell me why I am wrong that finding 2 chars that were both used the same number of times, not reporting non-alpha). In other words, address my points, don’t just insult me.

---

<div class="post-metadata">

**Author:** ![robsaye](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@robsaye](https://forum.codewithmosh.com/u/robsaye)\
**Post date:** [June 3, 2022, 9:40pm UTC](https://forum.codewithmosh.com/t/exercise-5-23-in-complete-python-mastery-course/12758/4 "2022-06-03T21:40:36Z")

</div>

By the way, if I was the moderator I would kick you off this site. Insulting beginner coders is a good way for Mosh to lose business.
