I have a question about how to properly construct functions in python that have side effects.
Let's say I have some code like this, that is supposed to remove occurrences of a number from a list:
def removeNumber(nums, val):
nums = [num for num in nums if num != val]
If i then use this code from outside the function like so:
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
removeNumber(my_list, 4)
print(my_list)
my_list remains unchanged, since nums is only a slot in memory that used to point to the same list as my_list, but that after my new assignment points to a new list that looks the way I'd like.
How would I go about changing my_list to point to the new list I have just created?
I know that referencing nums[n] will go to the actual list in memory, but I find that to be a bit clunky. Thanks!