12/15 purify


#1

I don't understand which part of my code is worng.
plz give me some advice.

def purify(number):
    list_number = list(number)
    for i in list_number:
        if i % 2 == 0:
            continue
        else:
            list_number.remove(i)
    return list_number

[12/15 purify](http://discuss.codecademy.com/t/12-15-purify/20255):
#2

Before we test this, what information can you add, such as error message(s), console messages, instructions that might be difficult to understand, etc.?


#3

As convenient as .remove() presents, the idea of altering a structure that we have intiated iteration of is not recommended. Instead, and since we are returning an object, create the object and return it,

def purify(numbers):
    nums = []
    for n in numbers:
        if n % 2 == 0:
            nums.append(n)
    return nums

#4

I wrote a very similar code :smile:
except I like to always start my variables with a,b,c...


#12

My solution isn't the most elegant, but it did work

def purify(num_list): 
    pure_list=[] #The pure list 
    odd_list=[] #The Rejects 
    #Loop through the list 
    for num_element in num_list: 
        if num_element % 2 == 0:
           pure_list.append(num_element)
        else: 
            odd_list.append(num_element)
    return pure_list;

#13

The way to remove duplicates from a list is to start fresh with an empty list. Begin appending items to the list based on whatever criteria you have (in this case the item is even). This is my flattest function so far. I'm happy I finally have something to contribute.

def purify(this):
purified = [x for x in this if x % 2 == 0]
return purified
purify([1,2,3])


#14

Where does the output go?

def purify(lst):
    return [x for x in lst if x %2 == 0]

print(purify([1,2,3,4,5,6,7,8,9])

#16

This may help me with Exercise 14!