반응형
Description:
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
Example: (Input --> Output)
"Dermatoglyphics" --> true
"aba" --> false
"moOse" --> false (ignore letter case)
Solution:
1. Change all 'string' to lower case and set type.
2. Compares the length of the original 'string' and the set 'string' and returns a Boolean value.
def is_isogram(string):
return len(set(string.lower())) == len(string)
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Sum of Odd Cubed Numbers (0) | 2022.04.14 |
---|---|
Century From Year (0) | 2022.04.13 |
Student's Final Grade (0) | 2022.04.11 |
Remove First and Last Character Part Two (0) | 2022.04.10 |
Total amount of points (0) | 2022.04.09 |