Python Arena

Module 45

List comprehensions

Building a new list from an old one in a single line. List comprehensions that change every item, pick only some items with if, choose between two values with if and else, and take the place of loops that build lists.

Steps

  1. A new list from an old one
  2. Picking items with if
  3. Choosing a value with if and else
  4. Comprehensions instead of loops