In python, remove_from_list(my_list, indices): Takes two lists as input. Creates a new list from the first input list by removing the elements at indices given by the integers in the second input list, then return the new list. The indices in the second input list may have any order. For example, if the first input list is [4, 8, 12, 16], and the second input list is [0, 2], then the new list returned from the function should have the 4 and the 12 removed, because they were at indices 0 and 2 of the original list. Note: You do not need to consider negative indices for this function. >>> remove_from_list(['abc', 'def', 'ghi'], [1]) ['abc', 'ghi'] >>> strs = ['The', 'quick', 'brown', 'fox'] >>> remove_from_list(strs, [0, 3]) ['quick', 'brown'] >>> strs ['The', 'quick', 'brown', 'fox'] # original list is unchanged >>> remove_from_list(['The', 'quick', 'brown', 'fox'], [3, 0]) ['quick', 'brown']
In python,
remove_from_list(my_list, indices): Takes two lists as input. Creates a new list from the first
input list by removing the elements at indices given by the integers in the second input list, then
return the new list. The indices in the second input list may have any order.
For example, if the first input list is [4, 8, 12, 16], and the second input list is [0, 2], then the
new list returned from the function should have the 4 and the 12 removed, because they were at
indices 0 and 2 of the original list.
Note: You do not need to consider negative indices for this function.
>>> remove_from_list(['abc', 'def', 'ghi'], [1])
['abc', 'ghi']
>>> strs = ['The', 'quick', 'brown', 'fox']
>>> remove_from_list(strs, [0, 3])
['quick', 'brown']
>>> strs
['The', 'quick', 'brown', 'fox'] # original list is unchanged
>>> remove_from_list(['The', 'quick', 'brown', 'fox'], [3, 0])
['quick', 'brown']
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images