Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

in python, "Write a function that takes a string and uses a list comprehension to return the vowels of the string" ##my idea here is to search each letter/element in the variable 'vowels' and see if there are any element matches in 'word' (i used the word "cornucopia") and then return vowels. def vl(word): _if w in word == v in vowels: __print i _else: __print 'no vowel letters!' ##im confused on using functions for strings compared to floats, as well as using index to search for a matching element between two strings.

OpenStudy (anonymous):

list comprehensions let you assemble a list logically, they're pretty powerful and very concise. Here is an example that does the opposite of what you need, except from a string literal instead of a variable. [x for x in "atest" if x not in ['a','e','i','o','u','y']] The whole thing is in square brackets to say that it's going to be a list, then you decide what it's going to be a list of, in this case 'x'. then you write the logic to decide what x is, 'for x in "atest" if ....' I've done many single line solutions on projecteuler using list comprehensions, they're pretty great once you wrap your head around them.

OpenStudy (anonymous):

excellent, thanks! i have a much greater understanding of it now!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!