+ 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")
20 ответов
+ 6
x=input()
count=0
for i in x:
count += x.count(i)
if count == len(x):
print('true')
else:
print('false')
+ 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")
+ 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
+ 3
word = str(input())
set_word = set(word)
if len(word) == len(set_word):
print('true')
else:
print('false')
+ 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())
+ 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")
+ 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);
}
}
+ 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")
+ 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")
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.
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”
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))
0
word = input()
duplicate = 0
for i in word:
if word.count(i)>1:
duplicate +=1
if duplicate > 0:
print('false')
else:
print('true')
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')
0
# another solution
import re
s=input().lower()
pattern=r'([a-z]).*\1'
if re.search(pattern,s):
print('false')
else:
print('true')
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?
0
str=input("enter a string")
#set() function removes duplictates
if len(str)==len(set(str)):
print("true")
else:
print("false")
0
word=input()
ab=list(word)
for i in range(len(ab)):
if ab.count(ab[i])>1:
print ("false")
break
else:
print ("true")
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')
0
How did you get 1K views bruh😂