Assessment for list comprehensions

May 21, 2014 • Jonathan Frederic

# List comprehension assesment

  1. What is a `list comprehension` in Python?
    A) An understanding of a list.
    B) A compact notation for generating lists.
    C) A function that parses and acts on a list as a whole.
    D) A list of things that Python understands.

  2. Can you use a list comprehension as a list filtering mechanism? I.e. if you
    had a list of first names, could you use a list comprehension to make a list
    of only the first names starting with an A in that list?
    A) Yes
    B) No
    C) Maybe

  3. A list comprehension produces
    A) An integer
    B) A boolean
    C) A comprehension
    D) A list

  4. What is the primary use case for a list comprehension instead of the more
    niave approaches available to a programmer?
    A) Readability
    B) Algorithm complexity
    C) Reduced memory footprint