Skip to content

Commit a4e7143

Browse files
authored
Merge pull request #104 from ikostan/main
Merge from master
2 parents 636ed9c + fd77905 commit a4e7143

File tree

6 files changed

+300
-0
lines changed

6 files changed

+300
-0
lines changed

isogram/.exercism/config.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"authors": [
3+
"behrtam"
4+
],
5+
"contributors": [
6+
"abhijitparida",
7+
"cmccandless",
8+
"Dog",
9+
"ikhadykin",
10+
"N-Parsons",
11+
"Nishant23",
12+
"olufotebig",
13+
"rever0f",
14+
"sdublish",
15+
"thomasjpfan",
16+
"tqa236",
17+
"yawpitch"
18+
],
19+
"files": {
20+
"solution": [
21+
"isogram.py"
22+
],
23+
"test": [
24+
"isogram_test.py"
25+
],
26+
"example": [
27+
".meta/example.py"
28+
]
29+
},
30+
"blurb": "Determine if a word or phrase is an isogram.",
31+
"source": "Wikipedia",
32+
"source_url": "https://en.wikipedia.org/wiki/Isogram"
33+
}

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":"25ac21afe50649b1997ad54abe10b08d","url":"https://exercism.org/tracks/python/exercises/isogram","handle":"myFirstCode","is_requester":true,"auto_approve":false}

isogram/HELP.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Help
2+
3+
## Running the tests
4+
5+
We use [pytest][pytest: Getting Started Guide] as our website test runner.
6+
You will need to install `pytest` on your development machine if you want to run tests for the Python track locally.
7+
You should also install the following `pytest` plugins:
8+
9+
- [pytest-cache][pytest-cache]
10+
- [pytest-subtests][pytest-subtests]
11+
12+
Extended information can be found in our website [Python testing guide][Python track tests page].
13+
14+
15+
### Running Tests
16+
17+
To run the included tests, navigate to the folder where the exercise is stored using `cd` in your terminal (_replace `{exercise-folder-location}` below with your path_).
18+
Test files usually end in `_test.py`, and are the same tests that run on the website when a solution is uploaded.
19+
20+
Linux/MacOS
21+
```bash
22+
$ cd {path/to/exercise-folder-location}
23+
```
24+
25+
Windows
26+
```powershell
27+
PS C:\Users\foobar> cd {path\to\exercise-folder-location}
28+
```
29+
30+
<br>
31+
32+
Next, run the `pytest` command in your terminal, replacing `{exercise_test.py}` with the name of the test file:
33+
34+
Linux/MacOS
35+
```bash
36+
$ python3 -m pytest -o markers=task {exercise_test.py}
37+
==================== 7 passed in 0.08s ====================
38+
```
39+
40+
Windows
41+
```powershell
42+
PS C:\Users\foobar> py -m pytest -o markers=task {exercise_test.py}
43+
==================== 7 passed in 0.08s ====================
44+
```
45+
46+
47+
### Common options
48+
- `-o` : override default `pytest.ini` (_you can use this to avoid marker warnings_)
49+
- `-v` : enable verbose output.
50+
- `-x` : stop running tests on first failure.
51+
- `--ff` : run failures from previous test before running other test cases.
52+
53+
For additional options, use `python3 -m pytest -h` or `py -m pytest -h`.
54+
55+
56+
### Fixing warnings
57+
58+
If you do not use `pytest -o markers=task` when invoking `pytest`, you might receive a `PytestUnknownMarkWarning` for tests that use our new syntax:
59+
60+
```bash
61+
PytestUnknownMarkWarning: Unknown pytest.mark.task - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
62+
```
63+
64+
To avoid typing `pytest -o markers=task` for every test you run, you can use a `pytest.ini` configuration file.
65+
We have made one that can be downloaded from the top level of the Python track directory: [pytest.ini][pytest.ini].
66+
67+
You can also create your own `pytest.ini` file with the following content:
68+
69+
```ini
70+
[pytest]
71+
markers =
72+
task: A concept exercise task.
73+
```
74+
75+
Placing the `pytest.ini` file in the _root_ or _working_ directory for your Python track exercises will register the marks and stop the warnings.
76+
More information on pytest marks can be found in the `pytest` documentation on [marking test functions][pytest: marking test functions with attributes] and the `pytest` documentation on [working with custom markers][pytest: working with custom markers].
77+
78+
Information on customizing pytest configurations can be found in the `pytest` documentation on [configuration file formats][pytest: configuration file formats].
79+
80+
81+
### Extending your IDE or Code Editor
82+
83+
Many IDEs and code editors have built-in support for using `pytest` and other code quality tools.
84+
Some community-sourced options can be found on our [Python track tools page][Python track tools page].
85+
86+
[Pytest: Getting Started Guide]: https://docs.pytest.org/en/latest/getting-started.html
87+
[Python track tools page]: https://exercism.org/docs/tracks/python/tools
88+
[Python track tests page]: https://exercism.org/docs/tracks/python/tests
89+
[pytest-cache]:http://pythonhosted.org/pytest-cache/
90+
[pytest-subtests]:https://github.com/pytest-dev/pytest-subtests
91+
[pytest.ini]: https://github.com/exercism/python/blob/main/pytest.ini
92+
[pytest: configuration file formats]: https://docs.pytest.org/en/6.2.x/customize.html#configuration-file-formats
93+
[pytest: marking test functions with attributes]: https://docs.pytest.org/en/6.2.x/mark.html#raising-errors-on-unknown-marks
94+
[pytest: working with custom markers]: https://docs.pytest.org/en/6.2.x/example/markers.html#working-with-custom-markers
95+
96+
## Submitting your solution
97+
98+
You can submit your solution using the `exercism submit isogram.py` command.
99+
This command will upload your solution to the Exercism website and print the solution page's URL.
100+
101+
It's possible to submit an incomplete solution which allows you to:
102+
103+
- See how others have completed the exercise
104+
- Request help from a mentor
105+
106+
## Need to get help?
107+
108+
If you'd like help solving the exercise, check the following pages:
109+
110+
- The [Python track's documentation](https://exercism.org/docs/tracks/python)
111+
- The [Python track's programming category on the forum](https://forum.exercism.org/c/programming/python)
112+
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
113+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
114+
115+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
116+
117+
Below are some resources for getting help if you run into trouble:
118+
119+
- [The PSF](https://www.python.org) hosts Python downloads, documentation, and community resources.
120+
- [The Exercism Community on Discord](https://exercism.org/r/discord)
121+
- [Python Community on Discord](https://pythondiscord.com/) is a very helpful and active community.
122+
- [/r/learnpython/](https://www.reddit.com/r/learnpython/) is a subreddit designed for Python learners.
123+
- [#python on Libera.chat](https://www.python.org/community/irc/) this is where the core developers for the language hang out and get work done.
124+
- [Python Community Forums](https://discuss.python.org/)
125+
- [Free Code Camp Community Forums](https://forum.freecodecamp.org/)
126+
- [CodeNewbie Community Help Tag](https://community.codenewbie.org/t/help)
127+
- [Pythontutor](http://pythontutor.com/) for stepping through small code snippets visually.
128+
129+
Additionally, [StackOverflow](http://stackoverflow.com/questions/tagged/python) is a good spot to search for your problem/question to see if it has been answered already.
130+
If not - you can always [ask](https://stackoverflow.com/help/how-to-ask) or [answer](https://stackoverflow.com/help/how-to-answer) someone else's question.

isogram/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Isogram
2+
3+
Welcome to Isogram on Exercism's Python Track.
4+
If you need help running the tests or submitting your code, check out `HELP.md`.
5+
6+
## Instructions
7+
8+
Determine if a word or phrase is an isogram.
9+
10+
An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.
11+
12+
Examples of isograms:
13+
14+
- lumberjacks
15+
- background
16+
- downstream
17+
- six-year-old
18+
19+
The word _isograms_, however, is not an isogram, because the s repeats.
20+
21+
## Source
22+
23+
### Created by
24+
25+
- @behrtam
26+
27+
### Contributed to by
28+
29+
- @abhijitparida
30+
- @cmccandless
31+
- @Dog
32+
- @ikhadykin
33+
- @N-Parsons
34+
- @Nishant23
35+
- @olufotebig
36+
- @rever0f
37+
- @sdublish
38+
- @thomasjpfan
39+
- @tqa236
40+
- @yawpitch
41+
42+
### Based on
43+
44+
Wikipedia - https://en.wikipedia.org/wiki/Isogram

isogram/isogram.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Isogram.
3+
4+
Determine if a word or phrase is an isogram.
5+
6+
An isogram (also known as a "non-pattern word") is a word or phrase
7+
without a repeating letter, however spaces and hyphens are allowed
8+
to appear multiple times.
9+
10+
Examples of isograms:
11+
12+
lumberjacks
13+
background
14+
downstream
15+
six-year-old
16+
17+
The word isograms, however, is not an isogram, because the s repeats.
18+
"""
19+
20+
21+
def is_isogram(string: str) -> bool:
22+
"""
23+
Determine if a word or phrase is an isogram.
24+
25+
An isogram is a word or phrase without repeating letters. Spaces and hyphens
26+
are allowed to appear multiple times, but alphabetic characters must be unique
27+
(case-insensitive).
28+
29+
:param string: The word or phrase to check
30+
:type string: str
31+
:returns: True if the string is an isogram, False otherwise
32+
:rtype: bool
33+
"""
34+
# empty string
35+
if not string:
36+
return True
37+
38+
letters: list[str] = [char for char in string.lower() if char.isalpha()]
39+
return len(letters) == len(set(letters))

isogram/isogram_test.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# These tests are auto-generated with test data from:
2+
# https://github.com/exercism/problem-specifications/tree/main/exercises/isogram/canonical-data.json
3+
# File last updated on 2023-07-19
4+
5+
import unittest
6+
7+
from isogram import (
8+
is_isogram,
9+
)
10+
11+
12+
class IsogramTest(unittest.TestCase):
13+
def test_empty_string(self):
14+
self.assertIs(is_isogram(""), True)
15+
16+
def test_isogram_with_only_lower_case_characters(self):
17+
self.assertIs(is_isogram("isogram"), True)
18+
19+
def test_word_with_one_duplicated_character(self):
20+
self.assertIs(is_isogram("eleven"), False)
21+
22+
def test_word_with_one_duplicated_character_from_the_end_of_the_alphabet(self):
23+
self.assertIs(is_isogram("zzyzx"), False)
24+
25+
def test_longest_reported_english_isogram(self):
26+
self.assertIs(is_isogram("subdermatoglyphic"), True)
27+
28+
def test_word_with_duplicated_character_in_mixed_case(self):
29+
self.assertIs(is_isogram("Alphabet"), False)
30+
31+
def test_word_with_duplicated_character_in_mixed_case_lowercase_first(self):
32+
self.assertIs(is_isogram("alphAbet"), False)
33+
34+
def test_hypothetical_isogrammic_word_with_hyphen(self):
35+
self.assertIs(is_isogram("thumbscrew-japingly"), True)
36+
37+
def test_hypothetical_word_with_duplicated_character_following_hyphen(self):
38+
self.assertIs(is_isogram("thumbscrew-jappingly"), False)
39+
40+
def test_isogram_with_duplicated_hyphen(self):
41+
self.assertIs(is_isogram("six-year-old"), True)
42+
43+
def test_made_up_name_that_is_an_isogram(self):
44+
self.assertIs(is_isogram("Emily Jung Schwartzkopf"), True)
45+
46+
def test_duplicated_character_in_the_middle(self):
47+
self.assertIs(is_isogram("accentor"), False)
48+
49+
def test_same_first_and_last_characters(self):
50+
self.assertIs(is_isogram("angola"), False)
51+
52+
def test_word_with_duplicated_character_and_with_two_hyphens(self):
53+
self.assertIs(is_isogram("up-to-date"), False)

0 commit comments

Comments
 (0)