Python | Isogram Problem!
Tags: challenge, beginners, python, 100daysofcode
Published: 2020-07-31 12:18:12

Hey everone, I wanna share my last challenge that I solved, it took me around 2 days! 
I know it could be easy for some of you even for beginners but it doesn't matter for me cause my goal is improving my coding skill and problem solving every single day.
Long story short!
Let's dive to the __Isogram Challenge__!
 
-------------------------------------------------
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/i7579hqewova7g9lchr6.jpg)<figcaption>__SOLVE IT!__</figcaption>
__Problem:__
```Markdwon
Determine if a word or phrase is an isogram.

An isogram (also known as a "nonpattern word"),
 is a word or phrase without a repeating letter,
 however spaces and hyphens are allowed to appear
 multiple times.

Examples of isograms:

- lumberjacks
- background
- downstream
- six-year-old

The word **isograms**,
is not an isogram, because the s repeats.
```
***

Let's break down the problem to the __3__ steps:
1. Making a function
2. We need to use __if statement__ to count if there's more than one item in our string!
3. we need to __loop__ over __if statement__ to check every item in our string!.

---

1._Making a function_:
```python
  def isogram(string):
       pass
```
2._if statement to count if there's one more item or not_:

```python
if string.count(item) > 1 :
            return False
```
3._for loop over **if statement** to check every item in given string_:

```python
for item in upper_string:
```

*after this steps we need to combine _number 2 and number 3_, like this:

```python
for item in upper_string:
        if upper_string.count(item) > 1 :
            return False
```
So we have a function:

```python
def isogram(string):
    
    for item in string:
        if string.count(item) > 1 :
            return False
    return True
```

If we test our program with a string like this:

```python
abc = isogram("A B C")
```
It will return __False__ !
Cause our program count spaces so we have two spaces in "A B C" string!
If your read the __Problem__  part carefully it says:
> spaces and hyphens are allowed to appear
 multiple times!
So:
```python
spaces = " "
hyphens = "-"
```
We need another step to complete our solution which is:
.
.
.
4._writing a __if statement__ for  spaces and hyphens to return __True__ if there's more than once_:
```python
spaces = " "
hyphens = "-"
if string.count(spaces)>1 or string.count(hyphens)>1:
      return True
```
and our string() function will be look like this:

```python 
def isogram(string):
    
    for item in string:
        spaces = " "
        hyphens = "-"
        if  string.count(item) > 1 :
            return False
        elif string.count(spaces) > 1 or string.count(hyphens) > 1:
            return True 
        else:
            pass
    return True
        
```

Let's test our program with another string:
```python
abc = isogram("A a B C")
print(abc)
```
Our program will return __True__!!!
But we have two letter _"A" and "a"_!
That's obvious cause there is a difference between Capital letters and small letter in every programming language!
and if you try :
```python
print(A is a)
```
the answer would be __False__.
So in our program we can make all letters Upper-Case(upper()) or Lower-Case(lower()), it's totally up to you, I prefer upper!
```python 
def is_isogram(string):

    upper_string = string.upper()
    
    for item in upper_string:
        spaces = " "
        hyphens = "-"
        if upper_string.count(item) > 1 :
            return False

        elif string.count(spaces) > 1 or string.count(hyphens) > 1:
            return True 
        else:
            pass
    return True
```
I need to say thank you my brother [Amir](https://dev.to/amirdarx), cause you're helping me a lot in this way.
***
Finally we  completed this challenge, if you have any suggestion to improve this solution and write more _Pythonic_, cleaner and more readable just let me know and leave a comment below my post, I'll appreciate it.
Thank you so much for reading my post.



Keep Moving Forward __ツ__

Code with __💛__

__🅑🅐🅝🅙🅘__