**purify**What is wrong in this code plz?


#1

def purify(ls):
    for item in ls :
        if item % 2.0 != 0.0 :
            return ls.remove(item)
    return ls    
print purify([1,2,3])

#2

@adn77790: Yeah, forget about my last post (that's why we edit it), what's the issue with it?


#3

Thanks for your reply ; well I think that's all, I have problems in return keyword


#4

@adn77790: Oh, glad it was just the return statement.
Edited my last post without a purpose, oh boy.

But just a really quick reminder; pay close attention to the return statments since it will force your code to go back to where the function was called.
In your code, the first return, won't return anything.


#5

lol :slight_smile: it's fine thanks by the way


#6

What, if any error messages are you being given?

Can you explain your reasoning for choosing to use a float as the modulus? Doesn't parity imply that a number is evenly divided by the integer, 2? And wouldn't the modulo be 0. I don't see where a float fits into this evaluation.

Removing items from a list we are iterating can have negative consequences that need to be carefully thought out and mitigated.


#7

It's okay i got it you are right :+1:


#8

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