id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

bryce.hulett@hotmail.com > scale_by_k
prev  |  next  |  chance

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.


scale_by_k([4, 1, 2, 0, 3]) → [4, 4, 4, 4, 1, 2, 2, 3, 3, 3]
scale_by_k([-4, 0, 3, 0, 1, 0, 8, 0, -2]) → [3, 3, 3, 1, 8, 8, 8, 8, 8, 8, 8, 8]
scale_by_k([2]) → [2, 2]

...Save, Compile, Run (ctrl-enter)

def scale_by_k(lst):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 290 Post-solution available

Copyright Nick Parlante 2017 - privacy