Question

LOVOU AWN 1. def remove_all_from_string(word, letter): i=0 3. while i<len(word)-1: if word[i] = letter: num = word.find(lette

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def remove_all_from_string(word, substring):
   i = 0
   while (word.find(substring) != -1):
       num = word.find(substring)
       word = word[:num] + word[num+len(substring):]
       i = 0
   return word
print remove_all_from_string("bananas", "na")

Add a comment
Know the answer?
Add Answer to:
LOVOU AWN 1. def remove_all_from_string(word, letter): i=0 3. while i<len(word)-1: if word[i] = letter: num =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX =...

    Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX):     message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user     num = int(input(message))     while num < MINN or num > MAXX:         print("Invalid choice!")         num = int(input(message))     #return result     return num #counts dupes def twoInARow(numbers):     ans = "No duplicates next to each...

  • def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or...

    def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...

  • What are the outputs for each question PYTHON Question 6 bools = [True, 0>-1, not not...

    What are the outputs for each question PYTHON Question 6 bools = [True, 0>-1, not not True, 2%2 == 0, True and False] index = 0 while bools[index]: index += 1 print(index) a) 0 b) 1 c) 2 d) 3 e) none of the above Question 7 for i in range(2): for j in range(1): print(i, j, end = " ") a) no output b) 0 0 1 0 2 0 c) 0 0 0 1 1 0 1 1...

  • Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word)...

    Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word) To run the function modify() defined above, we make the following call: result = modify('course', 's') Find and fix the errors in the function definition, lines (1) to (4), such that after the call is executed: • Variable result has the value 'courses' • 'new word is courses' is printed out. For each error found and fixed, you must indicate the following: • line...

  • # Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sV...

    # Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sVal + str(tree.getRootVal()) sVal = sVal + printexp(tree.getRightChild())+')' return sVal #### Functions and classes to help with Homework 6 #### You should not make any changes to the functions and classes in this file, #### but you should understand what they do and how they work. import sys ### This function will be re-defined in hw6.py. However, it is needed for ExpTree, ###...

  • convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [...

    convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [ ] if len(nums) == 1: return nums [0] # first find freq freq dict d = {} for num in nums: if num in d: d[num] -= 1 # reverse the sign on the freq for the heap's sake else: d[num] = -1 h = [] from heapq import heappush, heappop for key in di heappush(h, (d[key], key)) res = [] count = 0...

  • I need help for this assignment. Thank you!! # 5555555555555555555555555555555555555555555555555 # Returns the longest word (which has six or more # characters and contains the letter, e) from # the...

    I need help for this assignment. Thank you!! # 5555555555555555555555555555555555555555555555555 # Returns the longest word (which has six or more # characters and contains the letter, e) from # the parameter list - 4 marks Os Define the get_longest_e_word() function which is passed a list of strings as a parameter. The function returns the word in the list which has the most characters (i.e., the longest word) BUT only words which have 6 or more characters and contain the letter...

  • Write a python code that takes in an number 0-9 and prints out the word of...

    Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT