how can I make the original list passed though the function and modified, but don't return a new list instead add on to old list?
Solution 1:
You need to append
to, or extend
, the list.
>>> def append_squares(nums):
... nums.extend([n ** 2 for n in nums])
...
>>> nums = [2, 4, 6]
>>> append_squares(nums)
>>> nums
[2, 4, 6, 4, 16, 36]
Solution 2:
Instead of nums[i] = nums[i]**2
, do nums.append(nums[i]**2)