PYTHON PROBLEM Define a function generatecubed numbers that
PYTHON PROBLEM
Define a function generate_cubed( numbers ) that creates and return a list where the element at each index is equal to numbers[index]**3. Your solution must use a list comprehension.
 
 Example Usage:
 numbers = range( 7 )
 print generate_cubed( numbers )
 Run > Run Module
 [0, 1, 8, 27, 64, 125, 216]
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
def generate_cubed( numbers ):   #function to generate cubes
    for i, val in enumerate(numbers):   #iterate over the list
        numbers[i] = val * val * val   #set the cube of val to the current i
    return numbers   #return the altered list
numbers = [0,1,2,3,4,5,6]
 print (generate_cubed( numbers ))
---------------------------------------------------------
OUTPUT:
![PYTHON PROBLEM Define a function generate_cubed( numbers ) that creates and return a list where the element at each index is equal to numbers[index]**3. Your so PYTHON PROBLEM Define a function generate_cubed( numbers ) that creates and return a list where the element at each index is equal to numbers[index]**3. Your so](/WebImages/30/python-problem-define-a-function-generatecubed-numbers-that-1083254-1761569201-0.webp)
