Purify: Thats crazy and i cant see why!


Guys please look at this and see how it places an even numbers list in my list!! Where does this full of even numberslist come from!?? Just to debug where on earth those even numbers get in my list i appended my list "e" with the input list, "numbers", and it still places an even numbers list first!!

odd=[1, 3, 5, 7, 9]
def purify(numbers):
  #  for i in numbers:
  #      if i not in odd:
            return e

The interpreter message is this: Oops, try again. Your function fails on purify([1]).
It returns [[2, 4, 6, 8], [1]] when it should return []


You are appending the input list, rather than the single number of each iteration.

even = []
for i in numbers:
    if i not in odd:

Be sure to set even inside the loop so it is starts empty each time the function is called. That is why the even numbers are still there.


Uff thank you that really helped a lot.. at beginning i have coded just the same as you did, later to debug i changed it.. but this last warning solved the problem: to get the list definition INside the function!

Thank you:)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.