-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwords_with_duplicate_letters.py
57 lines (48 loc) · 2.16 KB
/
words_with_duplicate_letters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""Words With Duplicate Letters.
Given a common phrase, return False if any individual word in the phrase
contains duplicate letters. Return True otherwise.
Source:
https://edabit.com/challenge/WS6hR6b9EZzuDTD26
"""
def no_duplicate_letters(phrase: str) -> bool:
"""Check if each word has distinct letters in phrase."""
words = phrase.split(' ')
for word in words:
if len(set(word)) == len(word):
continue
else:
return False
return True
def main():
"""Run sample no_duplicate_letters functions. Do not import."""
assert no_duplicate_letters("Easy does it.") is True
assert no_duplicate_letters("So far, so good.") is False
assert no_duplicate_letters("Better late than never.") is False
assert no_duplicate_letters("Beat around the bush.") is True
assert no_duplicate_letters(
"Give them the benefit of the doubt.") is False
assert no_duplicate_letters(
"Your guess is as good as mine.") is False
assert no_duplicate_letters("Make a long story short.") is True
assert no_duplicate_letters("Go back to the drawing board.") is True
assert no_duplicate_letters(
"Wrap your head around something.") is True
assert no_duplicate_letters("Get your act together.") is False
assert no_duplicate_letters("To make matters worse.") is False
assert no_duplicate_letters("No pain, no gain.") is True
assert no_duplicate_letters(
"We'll cross that bridge when we come to it.") is False
assert no_duplicate_letters("Call it a day.") is False
assert no_duplicate_letters("It's not rocket science.") is False
assert no_duplicate_letters("A blessing in disguise.") is False
assert no_duplicate_letters("Get out of hand.") is True
assert no_duplicate_letters("A dime a dozen.") is True
assert no_duplicate_letters(
"Time flies when you're having fun.") is True
assert no_duplicate_letters("The best of both worlds.") is True
assert no_duplicate_letters("Speak of the devil.") is True
assert no_duplicate_letters("You can say that again.") is False
print('Passed.')
if __name__ == "__main__":
main()