def anti_vowel(text): s = "" vowels = "aeiouAEIOU" for i in text: if i not in vowels: s += str(i) return s
str() isn’t needed, given
i is of type string
the big problem with this solution, is that strings are immutable, so when you concatenate a string like you do here:
s += str(i)
a new string is created with the combined result (each iteration of the loop)
ideally, you should use a mutable data type (like a list) and then
.join() the list into a string, and return it
For the rest, its a good solution
Is this what ok solution would be?
def anti_vowel(text): s = "" ss =  vowels = "aeiouAEIOU" for i in text: if i not in vowels: ss += i print s.join(ss)
i would prefer to use
.append() over list extending method (
+=), but yes, that is the way to go
Oh yes, .append() would be right way since it is list. Thanks a lot for reply mate!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.