Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isogram #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion practice/isogram/isogram.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
def is_isogram(string):
pass
"""
Check if the input string 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.

Args:
string (str): The string to check.

Returns:
bool: True if the string is an isogram, False otherwise.

Examples:
>>> is_isogram("subdermatoglyphic")
True
>>> is_isogram("Alphabet")
False
"""
# Remove hyphens and spaces, and convert to lowercase
scrubbed = string.replace('-', '').replace(' ', '').lower()

# An isogram has no repeating letters, so the length of the string
# should be equal to the number of unique letters (the size of the set)
return len(scrubbed) == len(set(scrubbed))
Loading