+ 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")

20th Jul 2021, 4:14 PM
Lee 4 Code
Lee 4 Code - avatar
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'))
20th Jul 2021, 4:32 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Calvin Thomas JaScript NotAPythonNinja Did something happen here which I am not aware of?
22nd Jul 2021, 11:36 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
22nd Jul 2021, 5:47 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas, did you notice all the down votes by the answers? Why is that?
22nd Jul 2021, 11:49 AM
Lee 4 Code
Lee 4 Code - avatar
+ 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.
22nd Jul 2021, 2:14 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas, how and why would there be downvotes? Also, how do you tag someone in the comments?
22nd Jul 2021, 4:08 PM
Lee 4 Code
Lee 4 Code - avatar
0
Can anyone explain the negative points beside the questions? What is the validity of this?
22nd Jul 2021, 10:37 AM
Lee 4 Code
Lee 4 Code - avatar
0
Hatsy Rei, notice all the down votes besides the questions. Why?
22nd Jul 2021, 11:39 AM
Lee 4 Code
Lee 4 Code - avatar
0
Hatsy Rei Nope, I guess. I don't understand what Lee For Code had meant in his previous comment.
22nd Jul 2021, 11:42 AM
Calvin Thomas
Calvin Thomas - avatar
- 1
else letter != next_letter and letter_list[letter] == letter_list[next_letter]: gives a syntax error what have I missed?
20th Jul 2021, 5:40 PM
Lee 4 Code
Lee 4 Code - avatar
- 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
20th Jul 2021, 7:35 PM
Lee 4 Code
Lee 4 Code - avatar
- 2
how would I compare a letter in the list to another?
20th Jul 2021, 5:22 PM
Lee 4 Code
Lee 4 Code - avatar
- 2
Also prints result repeatedly 12 times
20th Jul 2021, 5:49 PM
Lee 4 Code
Lee 4 Code - avatar
- 2
Thank you! Studying that code now.
20th Jul 2021, 8:17 PM
Lee 4 Code
Lee 4 Code - avatar
- 2
Marked where? In the discussion topics?
20th Jul 2021, 8:23 PM
Lee 4 Code
Lee 4 Code - avatar
- 2
Thank you again
20th Jul 2021, 8:32 PM
Lee 4 Code
Lee 4 Code - avatar