Skip to content

Commit ced07a6

Browse files
committed
Completed isogram challenge, was fun
1 parent 1298784 commit ced07a6

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

isogram/.exercism/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"track":"python","exercise":"isogram","id":"949b475e2d7d4da49f8880074a30f57c","url":"https://exercism.io/my/solutions/949b475e2d7d4da49f8880074a30f57c","handle":"sinanata","is_requester":true,"auto_approve":false}

isogram/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Isogram
2+
3+
Determine if a word or phrase is an isogram.
4+
5+
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.
6+
7+
Examples of isograms:
8+
9+
- lumberjacks
10+
- background
11+
- downstream
12+
- six-year-old
13+
14+
The word *isograms*, however, is not an isogram, because the s repeats.
15+
16+
17+
## Exception messages
18+
19+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
20+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
21+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
22+
a message.
23+
24+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
25+
`raise Exception`, you should write:
26+
27+
```python
28+
raise Exception("Meaningful message indicating the source of the error")
29+
```
30+
31+
## Running the tests
32+
33+
To run the tests, run `pytest isogram_test.py`
34+
35+
Alternatively, you can tell Python to run the pytest module:
36+
`python -m pytest isogram_test.py`
37+
38+
### Common `pytest` options
39+
40+
- `-v` : enable verbose output
41+
- `-x` : stop running tests on first failure
42+
- `--ff` : run failures from previous test before running other test cases
43+
44+
For other options, see `python -m pytest -h`
45+
46+
## Submitting Exercises
47+
48+
Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/isogram` directory.
49+
50+
You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`.
51+
52+
For more detailed information about running tests, code style and linting,
53+
please see [Running the Tests](http://exercism.io/tracks/python/tests).
54+
55+
## Source
56+
57+
Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram)
58+
59+
## Submitting Incomplete Solutions
60+
61+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
406 Bytes
Binary file not shown.

isogram/isogram.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import re
2+
3+
def is_isogram(string):
4+
x = []
5+
cstring = re.sub(r"[-()\"#/@;:<>{}`+=~|.!?, ]", "", string)
6+
for i in cstring.lower():
7+
if i in x:
8+
return False
9+
else:
10+
x.append(i)
11+
return True

isogram/isogram_test.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import unittest
2+
3+
from isogram import is_isogram
4+
5+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.7.0
6+
7+
8+
class IsogramTest(unittest.TestCase):
9+
def test_empty_string(self):
10+
self.assertIs(is_isogram(""), True)
11+
12+
def test_isogram_with_only_lower_case_characters(self):
13+
self.assertIs(is_isogram("isogram"), True)
14+
15+
def test_word_with_one_duplicated_character(self):
16+
self.assertIs(is_isogram("eleven"), False)
17+
18+
def test_word_with_one_duplicated_character_from_the_end_of_the_alphabet(self):
19+
self.assertIs(is_isogram("zzyzx"), False)
20+
21+
def test_longest_reported_english_isogram(self):
22+
self.assertIs(is_isogram("subdermatoglyphic"), True)
23+
24+
def test_word_with_duplicated_character_in_mixed_case(self):
25+
self.assertIs(is_isogram("Alphabet"), False)
26+
27+
def test_word_with_duplicated_character_in_mixed_case_lowercase_first(self):
28+
self.assertIs(is_isogram("alphAbet"), False)
29+
30+
def test_hypothetical_isogrammic_word_with_hyphen(self):
31+
self.assertIs(is_isogram("thumbscrew-japingly"), True)
32+
33+
def test_hypothetical_word_with_duplicated_character_following_hyphen(self):
34+
self.assertIs(is_isogram("thumbscrew-jappingly"), False)
35+
36+
def test_isogram_with_duplicated_hyphen(self):
37+
self.assertIs(is_isogram("six-year-old"), True)
38+
39+
def test_made_up_name_that_is_an_isogram(self):
40+
self.assertIs(is_isogram("Emily Jung Schwartzkopf"), True)
41+
42+
def test_duplicated_character_in_the_middle(self):
43+
self.assertIs(is_isogram("accentor"), False)
44+
45+
def test_same_first_and_last_characters(self):
46+
self.assertIs(is_isogram("angola"), False)
47+
48+
49+
if __name__ == "__main__":
50+
unittest.main()

0 commit comments

Comments
 (0)