1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
larisa [96]
3 years ago
11

#Write a function called "replace_all" that accepts three #arguments: # # - target_string, a string in which to search. # - find

_string, a string to search for. # - replace_string, a string to use to replace every instance # of the value of find. # #The arguments will be provided in this order. Your function #should mimic the behavior of "replace", but you cannot use #that function in your implementation. Instead, you should #find the result using a combination of split() and join(), #or some other method. # #Hint: This exercise can be complicated, but it can also #be done in a single short line of code! Think carefully about #the methods we've covered. #Write your function here!

Computers and Technology
1 answer:
gulaghasi [49]3 years ago
7 0

Answer:

Here is the function replace_all:

def replace_all(target_string,find_string,replace_string):

   result_string = replace_string.join(target_string.split(find_string))  

   return result_string

#if you want to see the working of this function then you can call this function using the following statements:

target_string = "In case I don't see ya, good afternoon, good evening, and good night!"

find_string = "good"

replace_string = "bad"

print(replace_all(target_string, find_string, replace_string)

Explanation:

The above program has a function called replace_all that accepts three arguments i.e target_string, a string in which to search ,find_string, a string to search for and replace_string, a string to use to replace every instance of the value of find_string. The function has the following statement:

replace_string.join(target_string.split(find_string))  

split() method in the above statement is splits or breaks the target_string in to a list of strings based on find_string. Here find_string is passed to split() method as a parameter which works as a separator. For example above:

target_string = In case I don't see ya, good afternoon, good evening, and good night!

find_string = good

After using target_string.split(find_string) we get:

["In case I don't see ya, ", ' afternoon, ', ' evening, and ', ' night']

Next join() method is used to return a string concatenated with the elements of target_string.split(find_string). Here join takes the list ["In case I don't see ya, ", ' afternoon, ', ' evening, and ', ' night'] as parameter and joins elements of this list by 'bad'.

replace_string = bad

After using replace_string.join(target_string.split(find_string))  we get:

In case I don't see ya, bad afternoon, bad evening, and bad night!  

The program and output is attached as a screenshot.

You might be interested in
How do you reflect yourself in the topic (filters)​
Gnesinka [82]
In what topic ?? Please explain more
6 0
2 years ago
To save a presentation, tap or click the save button on the Blank
frozen [14]
If this is a true or false statement then the answer is true unless you have it on automatic save 
4 0
3 years ago
Someone please help! Please fill this out
solmaris [256]
A Would be the answer, Sir.!
5 0
3 years ago
5. Write a program to remove any duplicate letters from a word and display the new word maintaining the original order. For exam
dexar [7]

Answer:

word = input('Enter a single word: ', 's');

n = length(word);

nodupWord = [];

for i = 1:n

  dup = false;

  c = word(i);

  for j = 1:i-1

      if word(j) == c

          dup = true;

          break;

      end

  end

  if ~dup

      nodupWord = [nodupWord, c]; %add the non-duplicate char to end

  end

end

disp(['Adjusted word: ', nodupWord])

Explanation:

The code is in Python.

3 0
3 years ago
Which task can a company perform with intranets
Irina-Kira [14]

Answer:

C.) store data securely would be my choice

Hope This Helps!  Have A Nice Day!!

6 0
3 years ago
Other questions:
  • In the following statement:
    12·1 answer
  • Prompt the user for a string that contains two strings separated by a comma. (1 pt)Examples of strings that can be accepted:Jill
    5·1 answer
  • Select the best answer for the question. 19. While broadcasting a football game, the announcer exclaimed, "I can't believe it. C
    7·2 answers
  • The ________ multiple-selection PHP statement is used to handle decision making and can be used to replace multiple if and if...
    12·1 answer
  • What important information is added to the TCP/IP transport layer header to ensure communication and connectivity with a remote
    13·1 answer
  • The part of the computer that provides access to the internet is the?
    14·1 answer
  • Count the number of words in the string. A word is one or more non-blank characters separated by one or more blanks. My suggesti
    13·1 answer
  • You can find synonyms and disciplinary jargon in the ______, _______, and ______ in your search results. You can then use these
    13·1 answer
  • Why do software managers have to be generalists with a range of skills, rather than simply technical specialists?
    14·1 answer
  • Rosa is building a website for a multimedia company. She wants to add a drop-down menu functionality to the website's main page.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!