Question

In: Computer Science

Write a program that removes a target item (a string) from a list of strings, and...

Write a program that removes a target item (a string) from a list of strings, and
that will print out the list without the item. Do not use built-in functions other than
input, print, and append. Instead, you may generate a new list that does not
include the target item and you can use the append() function. Your program
should read two inputs: the target and the list. For example, if the input is “apple”
and the list is [‘berry’, ‘apple’, ‘pear’, ‘orange’], the outputs should be [‘berry’,
‘pear’, ‘orange’] .

Solutions

Expert Solution

I have implemented the code to remove the target in the list per the given description.

Please find the following Code Screenshot, Output, and Code.

ANY CLARIFICATIONS REQUIRED LEAVE A COMMENT

1.CODE SCREENSHOT :

2.OUTPUT :

3.CODE :

lst=[]
#Create a input list
s=input('Enter element to insert(stop to exit) : ')
while s!='stop':
  lst.append(s);
  s=input('Enter element to insert(stop to exit) : ')
#print the list
print("The list is : ",lst)
#read the target to remove
target=input('Enter target to Remove : ')
#Empty list to store the elements
lst2=[]
#Loop for each element in lst
for s in lst:
  #If the string in 's' is not equal to 'target'
  #then we append to the list2
  if s!=target:
    lst2.append(s)
#print the final result
print("The list after removing "+target+" : ")
print(lst2)

Related Solutions

Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
3. Write a Java program that generates a set of random strings from a given string...
3. Write a Java program that generates a set of random strings from a given string of same length where no character is ever repeated and characters belong to the original string. Examples Input: “Hello World” Output: “World oHlel”
Java Write a method that removes duplicates from an array of strings and returns a new...
Java Write a method that removes duplicates from an array of strings and returns a new array, free of any duplicate strings.
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
Write a program in C++ that will make changes in the list of strings by modifying...
Write a program in C++ that will make changes in the list of strings by modifying its last element. Your program should have two functions: 1. To change the last element in the list in place. That means, without taking the last element from the list and inserting a new element with the new value. 2. To compare, you need also to write a second function that will change the last element in the list by removing it first, and...
Write a C++ program that allows a user choose item to purchase from a list; ask...
Write a C++ program that allows a user choose item to purchase from a list; ask for the amount to calculate the cost of the purchase; offer to add a tip; add a delivery fee based on the subtotal; then calculate the total amount that the user needs to pay. ---------------------------------- ----- GROCERY SHOPPING ITEMS ----- Milk     - $5.99 / gallon Egg      - $6.99 / dozen Cheese   – $10.98 / 8oz Pasta    – $2.75 / packet ---------------------------------- Other Values to...
Write a C++ program that will make changes in the list of strings by modifying its...
Write a C++ program that will make changes in the list of strings by modifying its last element. Your program should have two functions: 1. To change the last element in the list in place. That means, without taking the last element from the list and inserting a new element with the new value. 2. To compare, you need also to write a second function that will change the last element in the list by removing it first, and inserting...
Write a program to print 2 strings. One string must be written by parent process and...
Write a program to print 2 strings. One string must be written by parent process and another string must be written by a child process In language C
Creating a list/tuple 4. Write a program to accept a string from the user, then replace...
Creating a list/tuple 4. Write a program to accept a string from the user, then replace the first letter with the last letter, the last letter with the middle letter and the middle letter with the first letter. E.g. “Billy” -> “yiBll”.
Write a program that uses Python List of strings to hold the five student names, a...
Write a program that uses Python List of strings to hold the five student names, a Python List of five characters to hold the five students’ letter grades, and a Python List of four floats to hold each student’s set of test scores. The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT