+ 1

Isogram detector

Hi all, This is a beginner question. I was doing the isogram detector challenge, where I am trying to identify input words that have two repeated vowels. In my script, I am attempting to take an input, split it into characters, then say if the character is equal to the character after it, to print true. I realize that my code (below) is incorrect because it compares a letter to a number: if char == word.index(char +1) I’m just not sure what to do. Am I on the right path? How do I solve this? Working code: word = input() def split(x): return [char for char in x] word = split(word) for char in word: if char == word.index(char + 1): print("true") else: print("false")

5th Apr 2020, 6:40 PM
Joel
20 Answers
+ 6
x=input() count=0 for i in x: count += x.count(i) if count == len(x): print('true') else: print('false')
14th Sep 2021, 6:24 AM
Mateo González Bufi
Mateo González Bufi - avatar
+ 4
this should work just fine : text = input() text = text.lower() for i in range(len(text)): if text.count(text[i]) > 1: print("false") exit(0) print("true")
30th Apr 2021, 2:45 AM
Stephan Haller
Stephan Haller - avatar
+ 3
Ok can try this... import re def is_isogram(stg): p = r'([aeiou])\1' if re.search(p, stg): return True return False x = input().lower() print(is_isogram(x)) https://code.sololearn.com/cwQzSy1G39cm/?ref=app
6th Apr 2020, 9:06 PM
Jolomi Tosanwumi
+ 3
word = str(input()) set_word = set(word) if len(word) == len(set_word): print('true') else: print('false')
16th Jul 2022, 5:14 AM
wqd dqwwdqwd
wqd dqwwdqwd - avatar
+ 2
By comparing the len of the word to its set, you can see if there are duplicates. This is because sets do not allow duplicates. And by forgoing the if else statements and printing the boolean directly, you make your code more efficient. word = input() print(str(len(word) == len(set(word))).lower())
29th Sep 2022, 9:06 AM
Eugene Teh
Eugene Teh - avatar
+ 1
Let me just address your current code although it may not exactly do what the challenge asked for. But it will do what you want. The if condition in your for loop should be if char == word[word.index(char) + 1]: but this print true or false but will still throw an error for the last character in word because index of 'word.index(char) + 1' will be out of range. To tackle this do a checking to break out of the loop when the last char is encountered. Something like this: for char in word: if char == word[-1]: break elif char == word[word.index(char) + 1]: print("true") else print("false") If you wanna make the code more pythonic, can do something like this; word = list(input()) for char in word: if char == word[-1]: break elif char == word[word.index(char) + 1]: print("true") else print("false")
5th Apr 2020, 8:20 PM
Jolomi Tosanwumi
+ 1
import java.util.HashSet; import java.util.Set; import java.util.Scanner; public class IsogramDetector { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // Prompt the user to enter a string String input = scan.nextLine(); // Convert the string to a set of characters Set<Character> charSet = new HashSet<>(); for (char c : input.toCharArray()) { charSet.add(c); } // Check if the set size is equal to the string length boolean isIsogram = charSet.size() == input.length(); System.out.println(isIsogram); } }
20th Dec 2022, 12:57 AM
Paul Cy
Paul Cy - avatar
+ 1
Why not using the set-funktion in python? Very short way to check if the word is an isogram word=input() x=set(word) if len(word)==len(x): print("true") else: print("false")
3rd Jan 2023, 4:34 PM
Fürst Fabi
+ 1
In my opinion, the most understandable solution. The set function is responsible for deleting identical characters in the list. If the same characters in a word are deleted, it is logical that the length of this word will be shortened. Accordingly, we can conclude that if the word is not shortened, then the characters in it are all different. x=list(input()) a1=list(set(x)) if len(x)!=len(a1): print("false") else: print("true")
9th Aug 2023, 11:36 PM
Николай Завгородний
Николай Завгородний - avatar
0
Are looking for adjacent vowels e.g "sleep", wood" or..... for example "sololearn" which has two 'o' that are not adjacent? edit:- Can you give examples of word(s) that would return True and some that would return False.
5th Apr 2020, 9:31 PM
rodwynnejones
rodwynnejones - avatar
0
Tosanwumi Jolomi thank you! that does get me closer to the answer. But it appears as though you’re right: this doesn’t solve the question posed by the challenge. Back to the drawing board. rodwynnejones I’m looking for words with adjacent vowels, like “sleep” and “wood”. Those should return “true” while others, like “octopus”, should return “false”
6th Apr 2020, 6:16 PM
Joel
0
import re def funct(mystring): pattern = r'\w*' + r'{2}\w*|\w*'.join("aeiou") + r'{2}\w*' if re.match(pattern, mystring): return True else: return False word = input() print(funct(word)) https://code.sololearn.com/c8BQCAHT0BMo/#py edit:- without using regular expresions:- def funct(mystring): for i in range(len(mystring)-1): if mystring[i] in "aeiou": if mystring[i] == mystring[i+1]: return True return False word = input() print(funct(word))
6th Apr 2020, 8:10 PM
rodwynnejones
rodwynnejones - avatar
0
word = input() duplicate = 0 for i in word: if word.count(i)>1: duplicate +=1 if duplicate > 0: print('false') else: print('true')
24th Jan 2022, 6:49 AM
Gareth Vaughan
Gareth Vaughan - avatar
0
#ignore letter case x=input().lower() #list w=list(x) #set:remove duplicates c=set(w) if len(c)==len(w): print('true') else: print('false')
11th May 2022, 11:24 PM
MING ZI CHEN
MING ZI CHEN - avatar
0
# another solution import re s=input().lower() pattern=r'([a-z]).*\1' if re.search(pattern,s): print('false') else: print('true')
12th May 2022, 12:29 AM
MING ZI CHEN
MING ZI CHEN - avatar
0
def isomer(word): for letter in word: if word.count(letter) <= 1: return("true") else: return("false") word = input() print(isomer(word)) This code worked for every test case except #2 which was the word “Cerebral” does anyone know why?
29th May 2022, 4:30 AM
#BLAKE
#BLAKE - avatar
0
str=input("enter a string") #set() function removes duplictates if len(str)==len(set(str)): print("true") else: print("false")
1st Sep 2022, 6:41 PM
Lakshmana Velpula
0
word=input() ab=list(word) for i in range(len(ab)): if ab.count(ab[i])>1: print ("false") break else: print ("true")
19th Nov 2022, 8:57 AM
Yevhen Lovkin
Yevhen Lovkin - avatar
0
Working code in 6 lines: txt, alb=input().lower() , "abcdefghijklmnopqrstuvwxyz" for i in alb: if txt.count(i) >1: print("false") exit(0) print('true')
21st Mar 2023, 11:34 AM
Danil Ryaboshtanov
0
How did you get 1K views bruh😂
17th Aug 2024, 4:32 PM
SatyaPrakash Mishra
SatyaPrakash Mishra - avatar