Question

3) What is a flaw with this code to remove all the "4" values from a...

3) What is a flaw with this code to remove all the "4" values from a list?

nums = [1, 3, 5, 4, 7, 8, 4, 4, 9, 1, 12] nums.remove(4)

------------------------------------------------------------------------------

4) What is the flaw with this code to remove all the "4" values from a list?

nums = [1, 3, 5, 4, 7, 8, 4, 4, 9, 1, 12]

spot = 0

while spot < len(nums):

if nums[spot] == 4:

del nums[spot]

spot = spot + 1

Homework Answers

Answer #1

Answer 3: It will remove the only first occurence of the 4. so it will not remove all 4's from the list

Answer 4:if we have two 4 consquetively than it can't remove it becuse we are increasing the spot here so when remove 4 size of list decrease and indexes changes

so if we have two 4's side by side by than we will skip the other 4

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Know the answer?
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
Similar Questions
# Python Given the list values = [], write code that fills the list with each...
# Python Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20 1 4 9 16 25 36 49 64 81 100 0 0 0 0 0 0 0 0 0 0 1 4 9 16 9 7 4 9 11 0 1 0...
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array....
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array. It stores 4 and 5 as the first and second elements, respectively, of the array. It adds the first and second elements of the array and stores their sum as the third element of the nums. It prints the third element of nums. It then adds the second and third elements of the array and stores their sum as the fourth element of nums....
A new set of measurements are obtained with the values 0, 1,2, 3, 4, 5, 6,...
A new set of measurements are obtained with the values 0, 1,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 and these values are found 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0 times, respectively. Find the the average value of the measurements and the statistical uncertainty based on the measurements.
1. Code is already written please show all outputs and comment on function of code. 2....
1. Code is already written please show all outputs and comment on function of code. 2. These are Python 3 programs. Please show outpouts and comment on fuctions. Note: this is a bit of a “backwards” exercise – we show you code, you figure out what it does. As a result, not much to submit – don’t worry about it – you’ll have a chance to use these in other exercises. >>> feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit...
1) You must implement a recursive Quicksort algorithm that will read integers from the attached MyList.txt...
1) You must implement a recursive Quicksort algorithm that will read integers from the attached MyList.txt file. Your algorithm must sort the list(integers)in ascending order. 2)You must implement a recursive Mergesort algorithm that will read integers from the attached MyList.txt file. Your algorithm must sort the list(integers)in ascending order. My List txt Values 7 3 4 1 4 4 9 9 4 8 4 5 3 9 2 3 7 0 6 4 4 5 0 1 9 2 1...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []        //create empty list to merge the lists M and N if not M:                //if M is empty list, m = 0                //set m = 0 else: m = len(M)             //otherwise, set m = len(M) if not N:                //if N is empty list, n = 0       ...
2.) In order to have a loop that allows the user to input 10 values, what...
2.) In order to have a loop that allows the user to input 10 values, what would be entered in the blank below: int counter = _________; while (counter < 10) { inputVal = Console.ReadLine(); ++counter; } 3.)What is produced from the following code segment? for (int i = 1; i < 5; i++) WriteLine(i); Nothing is displayed Outputs 5 thru 9 Outputs 10 Outputs 1 thru 4 Outputs 1 thru 5 Outputs 10 thru 14 Outputs 0 thru 4...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following questions using the list below. You can record your answers in the essay textbox. data = [5,3,7] A. Write code to replace the value in the 0 position with the number 8. B. Add the value 10 to the end of the list. C. Insert the value 22 after position 1 in the list. D. Remove the value at position 2. E. Sort the...
Appendix B.4 is a table of random numbers that are uniformly distributed. Hence, each digit from...
Appendix B.4 is a table of random numbers that are uniformly distributed. Hence, each digit from 0 through (including) 9 has the same likelihood of occurrence. (Round your answers to 2 decimal places.) picture Click here for the Excel Data File Compute the population mean and standard deviation of the uniform distribution of random numbers. Assume that 10 random samples of five values are selected from a table of random numbers. The results follow. Each row represents a random sample....
Appendix B.4 is a table of random numbers that are uniformly distributed. Hence, each digit from...
Appendix B.4 is a table of random numbers that are uniformly distributed. Hence, each digit from 0 through (including) 9 has the same likelihood of occurrence. (Round your answers to 2 decimal places Compute the population mean and standard deviation of the uniform distribution of random numbers. Assume that 10 random samples of five values are selected from a table of random numbers. The results follow. Each row represents a random sample. 0 2 7 1 1 9 4 8...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT