i coded this
def panagram(sen):
sen= sen.replace(" ","")
alphabets = ["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',1]
for words in sen:
for letter in words:
if letter.lower() in alphabets:
alphabets.remove(letter)
else:
pass
if len(alphabets)==1:
return "PANAGRAM"
else:
return "Not Panagram"
but when i run it i got an error
(PS i am a beginner this is my first question)
CodePudding user response:
The problem is that you removed the spaces from the string. When the first loop is run it, as there are no spaces in the string, it instead of considering words directly takes up the letters. For eg. if
sen = "The quick brown fox jumps over the lazy dog"
when you remove spaces, it becomes
"Thequickbrownfoxjumpsoverthelazydog"
The word then becomes a letter that means in first run
word = T
And then there is nothing itterable in a string character, that's why it gives error
You can either remove
sen= sen.replace(" ","")
Or the loop
for words in sen:
Just use
for letter in sen:
Also remove letter.lower() not lower, there is another problem in your string the letter h come twice, so when it is removed first time, there is nothing left to remove the second time, you can solve this by creating a set
a = set(sen)
Then you iterate through the set
Hope that helps!!