+ 3
Isogram confusion
Can't seem to connect the dots to have the code check for the same letter in the list. word = str(input()) letter_list = [word] for letter in letter_list: if letter != letter: print("true") else: print("false")
16 Respuestas
+ 6
Well, a couple of things here. To split a string to list, I'm pretty sure you need to use the list function.
letter_list = list(word)
otherwise [word] simply constructs a list which stores the string.
In the loop, letter is definitely always letter, they are the same variable so that's why the check wouldn't work. If you want to do it this way, you need to loop through each letter, and for each letter compare if the other letters are equal to it.
A more elegant solution would be to just use the list.count method.
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_list_count.asp
For each letter in the word, if you manage to count it more than once, then it isn't an isogram. Try looking at how this works:
print(list("word").count('w'))
+ 5
+ 3
Lee For Code Here's a possible solution:
word = input()
print("true" if all(word.count(x) < 2 for x in word) else "false")
# Hope this helps
+ 1
Calvin Thomas, did you notice all the down votes by the answers?
Why is that?
+ 1
Lee For Code I'm not sure about that. I had thought that all the downvoted comments were somewhat unrelated to the thread. It seems not.
+ 1
Calvin Thomas, how and why would there be downvotes? Also, how do you tag someone in the comments?
0
Can anyone explain the negative points beside the questions?
What is the validity of this?
0
Hatsy Rei,
notice all the down votes besides the questions.
Why?
0
Hatsy Rei Nope, I guess. I don't understand what Lee For Code had meant in his previous comment.
- 1
else letter != next_letter and letter_list[letter] == letter_list[next_letter]:
gives a syntax error
what have I missed?
- 1
An isogram is a word that has no repeating letters, whether they are consecutive or non-consecutive.
Your job is to find a way to detect if a word is an isogram.
Task: Write a program that takes in a string as input, detects if the string is an isogram and outputs true or false based on the result.
Input Format:
A string containing one word.
Output Format:
A string: true or false.
Sample Input:
turbulence
Sample Output:
false
- 2
how would I compare a letter in the list to another?
- 2
Also prints result repeatedly 12 times
- 2
Thank you!
Studying that code now.
- 2
Marked where?
In the discussion topics?
- 2
Thank you again