Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is my code, but I want you to check these code. And I do not know number 4

ID: 3663477 • Letter: T

Question

This is my code, but I want you to check these code. And I do not know number 4 and 6 right now.

def cube(T):     #1
    return(T*T*T)
a = list(range(1, 11))
print(a)
m = map(cube, a)
print(m)
print()

def divisible_3(T):   #2
    if(T % 3 == 0):
        return T
a = list(range(1, 11))
print(a)
f1 = map(divisible_3, a)
print(f1)
print()

def cube(T):     #3
    return(T*T*T)
a = list(range(1, 11))
print(a)
cube = [(T*T*T) for T in a]
print(cube)
print()

a = list(range(1, 11))     #5
print(a)
divisible_3 = [(if(T % 2 == 0): return T) for T in a]
print(div_3)
print()

a = list(range(1, 11))   #7
print(a)
divisible_3 = [(if(T % 2 == 0): return T) for T in a]
print(divisible_3)
print()

def findMin(x, y):     #8
    if (x < y) in return x else return y

From here, questions.

Let a be the list of values produced by list(range(1, 11)).

[1 point] Using the map function and a lambda argument, write an expression that produces a list of the cubes of the values in a. Assign the result to a variable called m and print m.

[1 point] Using the filter function and a lambda argument, write an expression that produces a list of the values in a that are divisible by 3. Assign the result to a variable called f1 and print f1.

[1 point] Using the reduce function and a lambda argument, write an expression that returns the result of concatenating all the digits in a. Assign the result to a variable called r1 and print r1. The output from this step is the string '12345678910'

[1 point] Use a list comprehension to produce the same list as in question 1 (i.e., the new list will contain the cubes of the values in a).

[1 point] Use a list comprehension to produce the same list as in question 2.

[1 point] Use a list comprehension to produce a list containing the cubes of the values in a that are divisible by 3. The output from this step is the list [27, 216, 729]

[2 points] Write a function named evenFilter that takes as an argument a dictionary of elements indexed by integer keys. Using only a list comprehension, return the values of the elements associated with the keys that are evenly divisible by 2. For example,

          >>> data = {1: "one", 3: "three", 4: "four", 5: "five", 8: "eight", 10: "ten"}
          >>> print(evenFilter(data))
          ['four', 'eight', 'ten']

[2 points] Write a function called findMin(x, y) that uses the ternary operator (i.e, conditional expression) to find and return the minimum of its two arguments. Assume that x and y are numbers. Write code to test this function.

Explanation / Answer

The code you wrote doesn't answer what was asked. The assignment question calls for the implementaion of the following major python concepts:

You did not use the lambda function. No worries, let me tell you what a lambda function is.

A lambda function is a 'quick use once and through' function. Unlike normal function which you can define once and call multiple times, lambda function is called once after it is defined. The 'cube' function that you wrote was a normal function. Here is how you would implement a lambda function to do the same work as the 'cube' function:

List comprehension in python can be used to construct lists in a very natural, easy way, like a mathematician is used to do.

Square numbers of the natural numbers are for example created by

In mathematics : M = { x2 | x }

In python : M = [ x**2 for x in N ]

Okay so, let me show you step by step answer to your assignment problem:

Let a be the list of values produced by list(range(1, 11)).

Using the map function and a lambda argument, write an expression that produces a list of the cubes of the values in a. Assign the result to a variable called m and print m.

Using the filter function and a lambda argument, write an expression that produces a list of the values in a that are divisible by 3. Assign the result to a variable called f1 and print f1.

Using the reduce function and a lambda argument, write an expression that returns the result of concatenating all the digits in a. Assign the result to a variable called r1 and print r1. The output from this step is the string '12345678910'

Use a list comprehension to produce the same list as in question 1 (i.e., the new list will contain the cubes of the values in a).

Use a list comprehension to produce the same list as in question 2.

Use a list comprehension to produce a list containing the cubes of the values in a that are divisible by 3. The output from this step is the list [27, 216, 729]

Write a function named evenFilter that takes as an argument a dictionary of elements indexed by integer keys. Using only a list comprehension, return the values of the elements associated with the keys that are evenly divisible by 2

Write a function called findMin(x, y) that uses the ternary operator (i.e, conditional expression) to find and return the minimum of its two arguments. Assume that x and y are numbers.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote