# How do I remove blank spaces from counting?

**URL:** https://forum.codewithmosh.com/t/how-do-i-remove-blank-spaces-from-counting/9957
**Category:** Python
**Created:** [January 14, 2022, 8:01pm UTC](https://forum.codewithmosh.com/t/how-do-i-remove-blank-spaces-from-counting/9957 "2022-01-14T20:01:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andy30](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Andy30](https://forum.codewithmosh.com/u/Andy30)
#### Post date: [January 14, 2022, 8:01pm UTC](https://forum.codewithmosh.com/t/how-do-i-remove-blank-spaces-from-counting/9957/1 "2022-01-14T20:01:29Z")

</div>

I am working on the python mastery example in his course where you try finding the most repeated character. I have the coding itself set up the way it showed in the solution. I decided to mess around with different sentences. The issue I have in the attached example is that spaces are the most repeater, so the value I get is (’ ', 8). How do I remove it from counting the spaces? I tried adding into the if char in charfreq section a statement that said: and not == " ", but get an error message. I tried adding an elif of saying char != " ", and did not work either. Any help would be appreciated.

 ![Screenshot_20220114-140050_Pydroid 3](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/8/8bcfd31b425684c7e11490421f05d25a2acb0c81.jpeg)

---

<div class="post-metadata">

### Author: ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)
#### Post date: [January 15, 2022, 12:01am UTC](https://forum.codewithmosh.com/t/how-do-i-remove-blank-spaces-from-counting/9957/2 "2022-01-15T00:01:27Z")

</div>

Maybe this?

```auto
sentence = "I went to the store to get some groceries"

charfreq = {}
for char in sentence:
  if char != " ":
    if char in charfreq:
      charfreq[char] += 1
    else:
      charfreq[char] = 1

charsorted = sorted(charfreq.items(), key=lambda kv:kv[1], reverse=True)

print(charsorted[0])

```

---

<div class="post-metadata">

### Author: ![Andy30](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Andy30](https://forum.codewithmosh.com/u/Andy30)
#### Post date: [January 15, 2022, 12:36am UTC](https://forum.codewithmosh.com/t/how-do-i-remove-blank-spaces-from-counting/9957/3 "2022-01-15T00:36:51Z")

</div>

That worked. Thanks!
