Question

.def remove(val, xs, limit-None): Remove multiple copies of val from xs (directly modify the list value that xs refers to). You may only remove up to the first limit occurrences of val. If limit -3, and xs had ten copies of val in it, then youd only remove the first three and leave the last seven in place. When limitNone, theres truly no limit (and we remove all occurrences of val). Return None, because the work happened in-place. Negative or zero limit: no removals. hint: if you need to traverse a list from front to back, but you dont always want to go to the next index location, while loops can be very useful - we dont have to step forward each iteratioin o o Note some test cases are multiple lines (which weve mostly avoided so far). You might need to notice the line number of a failed test, and go look at the code of that particular testing function, to see whats being attempted. Inspecting the actual testing code is a good habit to get into for projects. o Examples >> remove (1,xs) [2, 3, 4, 5] >> remove(1, xs,3)

python 3.6 please ! and comment your code

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

#here i am attaching the code.

def Remove(val,xs,limit):
a = []
if(limit==0): #if limit value is 0 then simply i am appending all elements to list a except val.
for i in xs:
if(i!=val):
a.append(i)
else: #in the else part i am leaving first limit matched values in xs and when limit cross then simply append value to list valled a.
count=0
for i in xs:
if(i==val and count<limit): #this is the condition to leave first limit range matched values.
count=count+1
continue
elif(count>=limit and i==val): #if limit value cross then append it to lisst a even it val==xs value.
a.append(i)
count = count + 1
else: # for remaining elements like val!=xs simply append to list a and then return.
a.append(i)
return a
xs = [1,2,1,3,1,4,1,5,1]
val = int(input("Enter Value which you want to remove from xs:"))
limit = int(input("Enter Limit value:"))
xs=Remove(val,xs,limit)
print(xs)

#here i am attaching output:

Run Debug Stop Share H Save Beautify Language Python 3 main.py 1 def Remove (val,xs,limit): 2 if (limit·0): #if limit value is θ then simply I am appending all elements to list a except val for 1 in XS: if(i!-val): 6 a.append (i) else: #in the else part 1 am Leaving first limit matched values in xs and when Limit cross then simply append valu 8 count-0 for 1 in XS: 10- if(1- val and countiinit): #this is the condition to Leave first Limit range matched values count-count+1 continue 12 13 elif(count >-limit and 1--val): #if Linnt value cross then append it to Lisst a even it val=ss value a.append(i) count count + 1 15 16 17 18 19 xs [1,2,1,3,1,4,1,5,1] 20 val-int (input (Enter Value which you want to remove from xs:)) 21 limit = int(input (Enter Limit value :)) 22 xs-Remove (val,xs,limit) 23 print(xs) else: # for remaining elements like val!-xs simply append to list a and then return. a.append (i) return a input Enter Value which Enter Limit value: 0 [2, 3, 4, 5] you want to remove from xs:1 ...Program finished with exit code 0#while reading my comments don't fear because of my english llittle bad to understand.

Add a comment
Know the answer?
Add Answer to:
python 3.6 please ! and comment your code .def remove(val, xs, limit-None): Remove multiple copies of...
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
  • please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each...

    please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available...

  • SCREENSHOTS OF CODE ONLY!! PLEASE DON'T POST TEXT!! C++ CODE! PLEASE DON'T REPOST OLD POSTS! Objective...

    SCREENSHOTS OF CODE ONLY!! PLEASE DON'T POST TEXT!! C++ CODE! PLEASE DON'T REPOST OLD POSTS! Objective To gain experience with the operations involving binary search trees. This data structure as linked list uses dynamic memory allocation to grow as the size of the data set grows. Unlike linked lists, a binary search tree is very fast to insert, delete and search. Project Description When an author produce an index for his or her book, the first step in this process...

  • **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the...

    **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the creatures from the classic science-fiction film "The Day of the Triffids") is an algorithm that enciphers a plaintext message by encoding each letter as a three-digit number and then breaking up and rearranging the digits from each letter's encoded form. For this assignment, you will create a set of Python functions that can encode messages using this cipher (these functions...

  • please answer "class playerexception(exception):" in python Notes Two players will face each other. They each decide...

    please answer "class playerexception(exception):" in python Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available to...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

  • 5. Please answer the following questions with respect to PLC Theory (8) a. Which phase of...

    5. Please answer the following questions with respect to PLC Theory (8) a. Which phase of the PLC is the pizza business? What indicators can you list? b. Given the phase of the PLC you indicated at part a: 1. What marketing mix strategies would you expect Dominos to be using? il. What marketing mix strategies is Dominos actually using? Ill. What disconnects, issues or questions arise from parts I and il above? The Strategy Carrying Domino's to New Heights...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

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