I'm trying to get each number that is not 6 into a separate list named valid. With my current knowledge with loops, i try to loop over each element in nums and append into 'valid', but it is not returning ALL NUMBERS that are != 6 (Not 6) even though i'm appending first then deleting the value. My current python version is 3.6
def sum6(nums):
valid = []
for item in nums:
if item != 6:
valid.append(item)
nums.remove(item)
else:
pass
print(valid)
print(nums)
sum6([1,2,3,6,4,5])
Prints valid:
[1,3,4]
Instead of[1,2,3,4,5]
Prints nums:
[2,6,5]
Instead of[6]