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...
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...
An access code consists of 3 letters of the alphabet followed by 3 digits. (Digits are...
An access code consists of 3 letters of the alphabet followed by 3 digits. (Digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.) How many different access codes are possible?
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....
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4,...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4, 5, 1}, {3,6,1,2}, {1,3,6,5}; Answer : 1- All values ​​of array2D are automatically 0 ? Yes or No 2- What is the value of array2D [3] .length ?________ 3-  The value that array2D.length shows is 12: Yes or No ? 4- Assign the value of 12 to the element in the third row, fourth column : 5- the value obtained when calculating array2D [1] [1]...
C++ PROGRAMMING Submit the code for each problem separately. Important: Please place all appropriate coding comments...
C++ PROGRAMMING Submit the code for each problem separately. Important: Please place all appropriate coding comments inside of the code. Problem 1    Create a simple linked list program to create a class list containing class node {             void *info;              node *next; public:              node (void *v) {info = v; next = 0; }              void put_next (node *n) {next = n;}              node *get_next ( ) {return next;}              void *get_info (...