I have this python practice question which is to return True if a word is an isogram (word with nonrepeating characters). It is also supposed to return True if the isogram is a blank string. My answer didn't work out.
from string import ascii_lowercase
def is_isogram(iso):
for x in iso:
return False if (iso.count(x) > 1) and (x in ascii_lowercase) else True
#None
While another answered:
def is_isogram(word):
word = str(word).lower()
alphabet_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in word:
if word.count(i) > 1 and i in alphabet_list:
return False
return True
#True
I'm not sure why the return value is different with just a slightly different structure or is it how to return statement is defined?
source https://stackoverflow.com/questions/74511050/why-does-python-return-none-in-this-instance
Comments
Post a Comment