Create a list of even numbers from a list

By Dave via Discussions on Python.org at 17Sep2022 09:34:

Thank you to all who took the time to comment and showed patience with
a new Python developer. The below code works !

Again, please use triple backticks:

 ```

instead of triple tildes:

Well, well, well. My apologies. It looks like triple tildes (~~~) are also accepted as code fences.

Dave, sorry about that.

Cheers,
Cameron Simpson

It is great that you made the program working. Just few notes:

  1. This code is redundant. You do not need the else: branch when you do nothing there.
        else:
            pass
  1. You do not need to make a list from args which is a tuple and can be iterated the same way as a list.
    for x in list(args):
  1. The body of the function is an ideal candidate for using a list comprehension. Later when you learn it you can try to change the function’s body to use a list comprehension. It can then contain just a single statement: return.

Vaclav:

I created this in under 5 mins. This worked perfectly. One line of code ! Thank you for the comprehension suggestion

Bravo!

Just two notes:

  1. Do not embed the data into the function. Get them as a parameter (as it was requested in the assignment). You probably do not want to write the function again for different data. This would be against one of the main reasons we use functions - to write the code just once and use it multiple times.
  2. In Jupyter you do not need to explicitly print the result. You just write for example myfunc(2, 3, 4) as the last statement in the cell and the result will be printed automatically.