This is python 3. Let a be the list of values by list(range(1, 11)) 1. Using the
ID: 3663396 • Letter: T
Question
This is python 3.
Let a be the list of values by list(range(1, 11))
1. 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.
2. Using the filter function and a lambda argument, write an exression 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.
3. Using the reduce function adn a lambda argument, write an expression that retruns the result of concatenating all the digits in a. Assign the result to a variable called r1 and print r1.
4. 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.)
5. Use a list comprehension to produce the same list as in question2.
6. 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]
7. Write a function named evenFilter that takes as an argument a dictionary of element indexed by integer keys. Using only a list comprehension, return the values fo the elements associated with the keys that are evenly divisible by 2.
8. Write a function called findMin(x, y) that uses the ternary operator(i.e. conditional expression) to find and retrun the minimum of its two arguments. Assume that x and y are numbers. Write code to test this function.
Explanation / Answer
Q1
def cube(T):
return (T*T*T)
a=list(range(1, 11));
print a
m=map(cube,a)
print m
Q2
def div_3(T):
if(T%3==0):
return T;
a=list(range(1, 11));
print a
f1=map(div_3,a)
print f1
Q4.
def cube(T):
return (T*T*T)
a=list(range(1, 11));
print a
cube = [(T*T*T) for T in a ]
print cube
Q5.
a=list(range(1, 11));
print a
div_3 = [(if(T%3==0):return T) for T in a ]
print div_3
Q7.
a=list(range(1, 11));
print a
div_2 = [(if(T%2==0):return T) for T in a ]
print div_2
Q8.
def findMin(x,y)
if(x<y) in return x else return y
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.