University of Arizona, Department of Computer Science

CSc 120: List Comprehensions 01

Expected Behavior

Write a Python function times_k(L, k) that takes as arguments a list L and an integer k, and returns a list consisting of the elements of L each multiplied by k.

Your solution should use list comprehensions only. It should not use any other control statements—i.e., no if, for, while, or try statements, except as needed within the list comprehension.

Examples

  1. Call: times_k([11,22,33], 3)
    Result: [33,66,99]

  2. Call: times_k([11,22,33], 0)
    Result: [0,0,0]

  3. Call: times_k([], 10)
    Result: []

  4. Call: times_k([20], 10)
    Result: [200]