iteration - function doesn't continue to loop -


my function acting little bit weird.

def cow_latinify_sentence(sento): ''' converting english cow latin '''     alpha = list("bcdfghjklmnpqrstvwxyz")     finale = []     worda = ""     word in sento.split():         finale.append(word)     in finale:         if i[0].lower() in alpha:             lista = list(i.lower())             worda = worda.join(lista[1:] + [lista[0]]) + "oo"                      else:             return word + "moo"                 return worda 

when run sentence like:

cow_latinify_sentence("cook me eggs") 

it returns: ookcoo. correct, doesn't loop around other words in sentence.

the function should return: ookcoo emoo omesoo eggsmoo

in addition that, if have sentence like:

cow_latinify_sentence("aran likes art") 

it returns last element (artmoo) in sentence being converted

so i'm guessing issue loops. i've tried changing positions of return statement , got funny results well.

when return worda, return first word , function stops executing. thus, won't return else.

in python, suggest use called list comprehension. details on how works, please search google. give example of how apply case here.

alpha = list("bcdfghjklmnpqrstvwxyz") def cow_latinify_word(word):     if word[0].lower() in alpha:         lista = list(word.lower())         return lista[1:] + [lista[0]] + "oo"     else:         return word + "moo"  def cow_latinify_sentence(sentence):     words = sentence.split();     return [ cow_latinify_word(word) word in words] 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -