Question

In Python define a function remove_indices which is given a list of items and a list...

In Python

define a function remove_indices which is given a list of items and a list of indices to remove. Remove the given indices in place (no extra memory) in linear time

Homework Answers

Answer #1

Complete code in Python3:-

# This function removs Elements from 'Items' list
# At indices stored in 'Indices'.
def remove_indices(Items, Indices):
   # Marking those Items as 'None' which will be deleted.
   for i in Indices:
       Items[i] = None
   # Traversing Items list and removing 'None' Items
   i = 0
   while i < len(Items):
       if Items[i] is None:
           del Items[i]
       else:
           i += 1

# List of Items
Items = [1, 2, 3, 4, 5, 6, 7, 89, 78]
# Printing List of items before removal
print("List before removing : ", Items)
# List of Indices that will be removed form the List fo Items.
Indices = [4, 2, 5, 8]
# Removing Indices from list
remove_indices(Items, Indices)
# Printing List of Items after removal
print("List after removing : ", Items)

Screenshot of output:-

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
question: Complete the function remove number such that given a list of integers and an integer...
question: Complete the function remove number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. please edit the Python form without errors def remove_number(lst: List[int], number: int) -> None:     """         Remove every instance of number in lst. Do this         *in-place*, i.e. *modify* the list. Do NOT         return a new list....
In python.....Create a Linked List program using at least 15 items. Must use the following in...
In python.....Create a Linked List program using at least 15 items. Must use the following in your program: Min() Max() Index() Count() Remove() Note: Use the "print" statement after each method.
Create a function which returns the number of odd integers in a list (python)
Create a function which returns the number of odd integers in a list (python)
Implement in python a function avg_val(lst), which returns the average value of the elements in list....
Implement in python a function avg_val(lst), which returns the average value of the elements in list. For example, given a list lst: [19, 2, 20, 1, 0, 18], the function should return 10. The name of the method should be avg_val and the method should take one parameter which is the list of values to test. Here is an example call to the function print(avg_val([19, 2, 20, 1, 0, 18]))
Write a Python function which receives 3 lists as its input parameters and combines the lists...
Write a Python function which receives 3 lists as its input parameters and combines the lists and remove repeated numbers from the combined list and return the combined list. For instance, if the input is [1,2,3,4,2,3] and [3,4,6,7] and [-1,0,23,4] the result is [1,2,3,4,6,7,-1,0,23] - Note, the order the lists are combined together does not matter. Use main function.
in python For a list of 100 items, the index of the last item is: (please...
in python For a list of 100 items, the index of the last item is: (please don't use negative indexing here...) Answer:
Implement function reverse that takes a 2D list (a list of list of integers) and returns...
Implement function reverse that takes a 2D list (a list of list of integers) and returns a new 2D list where the items in each row are in reverse order. You maynot use slicing. You may not modify the input list. The returned list should be completely new in memory – no aliases with the input 2D list. From list methods, you may use only the .append(). Examples: reverse([[1,2,3],[4,5,6]])       ->    [[3,2,1],[6,5,4]] reverse([[1,2],[3,4],[5,6]])     ->    [[2,1],[4,3][6,5]] True False In python please
Python The function cube should receive a list as a parameter and return a new list...
Python The function cube should receive a list as a parameter and return a new list with each number taken in cubic (raised to three). Write the necessary code for the function, as well as an example which uses the function to calculate and print the cubes for the numbers 5, 8 and 9
Implement function swap that takes a 2D list (a list of list of integers) and modifies...
Implement function swap that takes a 2D list (a list of list of integers) and modifies it in-place by swapping the first element in each row with the last element in that row. The return value is None. You may not use slicing. You maynot use any list method like append, insert, etc. Modification must be in-place, you may not move the list itself or any of its sublists to a new memory location. Examples: reverse([[1,2,3],[4,5,6]])        ->    [[3,2,1],[6,5,4]] reverse([[1,2,3,4],[5,6,7,8]])    ->    [[4,2,3,1],[8,6,7,5]]...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT