logo CodeStepByStep logo


Language/Type: Python lists collections

Write a function named scale_by_k that accepts a list of integers as a parameter and replaces every integer of value k with k copies of itself. For example, if the list stores the values [4, 1, 2, 0, 3] before the function is called, it should store the values [4, 4, 4, 4, 1, 2, 2, 3, 3, 3] after the function finishes executing. Zeroes and negative numbers should be removed from the list by this function.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.