+ 1
Create a method called is_isogram that takes one argument, a word to test of it's an isogram.
This method should return a tuple of the word & a boolean indicating whether its an isogram.
12 Antworten
+ 8
anyway, here's my solution for it
1) make it case-insensitive by converting to lowercase
2) build a list of letter counts
3) return True if the set of those letter counters is 1, else, return False
4) ?????
5) profit
def is_isogram(word):
# convert word to lower case
word=word.lower()
return len(set([word.count(letter) for letter in word]))==1
+ 6
@Justin
while being a nice solution that implementation will work for one occurance only (as you stated yourself).
as an isogram can have a letter repeat multiple times (as long as ALL the letters repeat the same amount as well) that implementation won't work for the latter cases
+ 6
"a word or phrase without a repeating letter. It is also used by some to mean a word or phrase in which each letter appears the same number of times, not necessarily just once."
go figure hehe
+ 6
seems you are right about the examples hehe
every word with no letter repeats
+ 5
Tell us what have you do to solve the problem, and in what part you are not understanding so that we can help you solve the problem and not solve it for you.
+ 5
from wikipedia:
"An isogram (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. It is also used by some to mean a word or phrase in which each letter appears the same number of times, not necessarily just once.
Conveniently, the word itself is an isogram in both senses of the word, making it autological."
edit:
possible solution in my codes
edit #2:
discovered an error in my implementation, all fixed now xD
+ 1
your right, I will add a check for equal amount of letters after I eat. I just find it hard to believe an isogram can be both a word with no repeating letters and also be a word with equal repeaters. seems like one or the other is wrong
+ 1
every example (there are alot) that wiki provides are for no repeats
+ 1
thanks y'all, solved the problem
0
def isoCheck(x):
iso=[]
for i in x:
if i in iso:
return "No " + x +" is NOT an isogram"
else:
iso.append(i)
return "Yes, " + x + " is an isogram"
run=True
while run == True:
isogram=input("\nEnter Word To Check-\n")
print(isoCheck(isogram))
My codes are never people's favorite way to do things, but they work. Assuming an isogram is a word with no repeating letters, my function isoCheck() does the trick
0
def isIso(word):
word = word.lower()
multi_true = len(word)/len(set(word))==int(len(word)/len(set(word)))
single_true = len(set(word))==len(word)
return(word,single_true or multi_true)