Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Tasks Implement each of the following functions. def simple pig latin (input, se

ID: 3805560 • Letter: T

Question

Tasks Implement each of the following functions. def simple pig latin (input, sep end Accept a string input, which might include multiple words separated by a separator sep and perform the following steps: o Find the list of "words" (Note: "words" are just "zero or more characters separated by a symbol". So, depending on the separator or 'a..b' could be a "word".) o Inspect every "word" and apply the following conversions: if the word starts with a non-letter or contains no characters, do nothing to it if the word starts with a vowel, add 'way' to the end if the word starts with a consonant, place the first letter at the end and add 'ay o Reassemble the words back into one string and return it, making sure a single sep is padded between any two neighboring words and the final string ends with end o Assume: the input does not have any capital letters o Go ahead and use string methods like .join(), .split() Examples: simple pig latin ("i like this") iway ikelay histay default sep (space) and end(dot) simple pig latin ("i like this i like this way sep separator is dot so whole thing is a single word o simple pig latin ("i-like- this iway-ike lay-histay. sep is and default end(dot) o simple pig latin ("i.like.this sep end iway histay and end is sep is o simple pig latin only word is so do nothing to it and add a to the end def replace (xs,old,new,limit None) Given a list xs, replace occurrences of old value with new value. An optional fourth argument limit is an integer states the maximum number of replacements allowed. You should only replace up to the first limit occurrences of old and leavethe rest unchanged. When limit None, there's truly no limit (and we replace all occurrences of old0 Negative or zero limit: no replacement. xs is a list, xs could be empty o Assume: n None, because the replacement happened in-place. Examples xs [1,2, 1,3,1 4,1,5,11 replace 1) #returns None XS -1, 3,-1, 4, -1, 5, -11 #replace all xs [1,2,1,3,1 1,5,1] replace 1,2) XS -1, 3, 1, 4, 1, 5, 11 #replace only the first 2 occurrences [1,2, 1,3,1 4,1,5,11 XS replace (xs, 1,-1, -100) XS 1, 3, 1, 4, 1, 5, 11 [1 #replace none

Explanation / Answer

remove the print() statements

1 > ############################################## simple_pig_latin

def simple_pig_latin(input, sep=" ", end="."):
word_list = list(input.split(sep))

for i in range(0,len(word_list)):
word = word_list[i]
vowels = ('a','e','i','o','u');
  
if(word[0].isalpha()):
if(word[0].lower() in vowels):
word = word + "way";
else:
word = word[1::] + word[0] + "ay"
  
word_list[i] = word;
  
return sep.join(word_list) + end
pass


input = "i like this"

print(simple_pig_latin(input,sep="."))

2 > ############################################## replace

xs = [1,2,1,3,1,4,1,5,1]
def replace(xs, old, new, limit=None):

# new limit will number of old in the list when limit is None
limit = limit if (limit < len(xs)) else xs.count(old)
  
i=0;
while(limit>0):
if(xs[i] == old):
xs[i] = new
limit -= 1;
i+=1
return None

replace(xs,1,-1,5)
print(xs)

3> #################################################### extract_negatives

def extract_negatives(xs,new_home=None):
  
new_home = [] if (new_home is None) else new_home
i = 0;
for item in xs:
if(item < 0 ):
new_home.append(xs.pop(i))
i+=1
  
return new_home
pass

print(extract_negatives(xs))
print(xs)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote