Category: basics

Problem

Filter elements with list comprehension.

Solution

  evens = [x for x in nums if x % 2 == 0]
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path