Snippet
def remove_all_occurrences(inp_list, val):
= 0
i while i < len(inp_list):
if type(inp_list[i]) == list:
remove_all_occurrences(inp_list[i], val)if len(inp_list[i]) == 0:
inp_list.pop(i)else:
+= 1
i elif inp_list[i] == val:
inp_list.pop(i)else:
+= 1
i
= [1, 2, 3, 2, 4, 2, 5]
my_list 2)
remove_all_occurrences(my_list, print(my_list)
= [2, [1, 2, [2, 3]], 4, 2] # you can ignore the type on this -- types in python are funky
my_sec_list # this does not mean ignore types -- this is just one exception
2)
remove_all_occurrences(my_sec_list, print(my_sec_list)
Solution
Note: The RA of the first remove_all_occurences frame should be 16 not 15.
Image Description
(Coming Soon)