CSCI0050 Python Practice
1 An Example Function Using Filter
CSCI0050 Homework: Warming up n Python

This is not a graded assignment. You are NOT required to submit it. These problems are only to help you practice the transition of Python, should you feel you need the practice.

1 An Example Function Using Filter

Here is an example of using filter in Python to select items from a list. It is very similar to filter in Pyret, except for the return type. In Python, filter returns a result that isn’t a list, but is easily converted to one by using the list operator, as shown in the code below"

  def rem_item_by_descr(descr: str, todoLst: List[ToDoItemType]) -> List[ToDoItemType]:

      """remove item with given description from list"""

      return list(filter(lambda item: item.Descr == descr, todoLst))

Exercises

Continue expanding the to-do list exercise that we started in class by adding the following:

Tips and Hints

To run your file and check for syntax errors in PyCharm, click the green arrow that appears to the right of the number for line 1 in the file editor. That will run your file, displaying the results of all print statements in the lower console. If you don’t have errors and you don’t have print statements, nothing will appear in the console except a message that your code "finished with exit code 0". This result actually means that everything was fine.

If you aren’t getting the green arrow, try adding adding then removing a space inside a variable name (that does the trick for me). I’ve also found that I am more likely to get the arrow when my file is within a project, rather than on its own. Go to "New Project" under the file menu, open the new project in a NEW window, then copy your existing code to the new file (you only need to do this once).

Files save automatically every time you press the run button.