def embedded_sounds (msg): We define a sound as a single vowel with a consonant
ID: 3587715 • Letter: D
Question
def embedded_sounds (msg): We define a sound as a single vowel with a consonant on each side of it (exactly three letters long; upper and lowercase all used). Given a message string or arbitrary length, construct the list containing all embedded sounds from the message, in the order they appear o o o o o Assume: msg is a string of any length. There are only five vowels: "aeiou". Restrictions: no extra restrictions embedded-sounds ("HOTDOG") [ ] embedded sounds ("totoro" embedded-sounds("George Mason University") ["Has", "son " , "niv" "ver","sit"] "HOT" ,"DOG" "tot", "tor"Explanation / Answer
def embedded_sounds(msg):
list1 = ["a","e","i","o","u","A","E","I","O","U"]
list2 = []
for i in range(len(msg)):
if msg[i] in list1:
str = ""
if i+1 < len(msg) and i-1 > -1:
if msg[i-1] != ' ' and msg[i+1] != ' ':
if msg[i-1] not in list1 and msg[i+1] not in list1:
str = msg[i-1] + msg[i] + msg[i+1]
list2.append(str);
return list2
print(embedded_sounds("HOTDOG"))
print(embedded_sounds("totoro"))
print(embedded_sounds("George Mason University"))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.