Purify


#1

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/purify?action=lesson_resume
What’s wrong with my code?
I do not get the expected output

def purify (list_arg):
  for item in list_arg:
    if item % 2 == 1:
      list_arg.remove(item)
  return list_arg

#2

to get output, you need to call the functions.

remember that functions do not execute unless called

uhm… .remove() is a difficult approach given you have to deal with index shift which causes succesive uneven/odd numbers to be skipped


#3

Hi, @designwhiz61809 ,

The instructions include this …

Do not directly modify the list you are given as input; instead, return a new list with only the even numbers.

That is good advice, in part because of the issue raised above by @stetim94 regarding the remove method.


#4

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