Question

I need to rewrite this code without using lambda function using python. def three_x_y_at_one(x): result =...

I need to rewrite this code without using lambda function using python.

def three_x_y_at_one(x):
result = (3 * x *1)
return result
three_x_y_at_one(3) # 9

zero_to_four = list(range(0, 5))

def y_values_for_at_one(x_values):
return list(map(lambda x : three_x_y_at_one(x), x_values)) -------> this is the function that I need to rewrite without using a lambda function .

y_values_for_at_one(zero_to_four) # [0, 3, 6, 9, 12]

Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have modified the code using PYTHON PROGRAMMING LANGUAGE .

OUTPUT :

CODE :

#function definition for three_x_y_at_one

def three_x_y_at_one(x):

result = (3*x*1)

return result

#to call three_x_y_at_one and print the result on console

print(three_x_y_at_one(3))

zero_to_four = list(range(0,5))

def y_values_for_at_one(x_values):

result = []

#using for loop accessing each value in x_values and calling

#three_x_y_at_one and adding result to list result.

for value in x_values:

temp = three_x_y_at_one(value)

result.append(temp)

return result#return result

#calling y_values_for_at_one and printing the result on console

print(y_values_for_at_one(zero_to_four))

Thanks..

Add a comment
Know the answer?
Add Answer to:
I need to rewrite this code without using lambda function using python. def three_x_y_at_one(x): result =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to rewrite this lambda function into a def function using python. mp is an...

    I need to rewrite this lambda function into a def function using python. mp is an dictionary. Thanks mp = sorted(mp.items(), key = lambda x : -x[1]) print(mp[:10])

  • Without using lambda in PYTHON How can I find the word "Code" and "code" on a...

    Without using lambda in PYTHON How can I find the word "Code" and "code" on a website and print how many times they appear?

  • I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import...

    I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2):     product = num1 * num2     result = a.add(product, product)     return result     def main():     num1 = 4     num2 = 3     answer = multiply(num1, num2)     print("The answer is", answer) if __name__ == "__main__":     main() arithmetic module: def add(x, y):     z = x + y     return z Refer to Code...

  • Consider the following Python program, where x is assumed to be a list of integers. def...

    Consider the following Python program, where x is assumed to be a list of integers. def mystery_func(x): n = len(x) for i in range(n - 1): for j in range(i + 1, n): if x[j] - x[i] < j - i: return False return True 3a. In plain English, describe what it accomplishes (i.e., the relationship between input and output, not how the code works). 3b. Analyze the running time and express it with big O. 3c. Rewrite this function...

  • In python and without using Libraries (comment the code and please don't use lambda code): Write...

    In python and without using Libraries (comment the code and please don't use lambda code): Write a function called mostfrequent that takes one string argument containing a list of words separated by commas (e.g., “apple,banana,apple,pear”, note there are no spaces). The function must return the word that occurs most frequently in the input string. You can assume there will be no ties in frequency. Examples: mostfrequent(“apple,apple,banana,apple,peach,banana”)  “apple” mostfrequent(“apple,banana,banana,apple,peach,banana”)  “banana” mostfrequent(“apple”)  “apple”

  • Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our...

    Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here

  • Python This is the code we are using: def main (): video_file = open ( 'video_times.txt')...

    Python This is the code we are using: def main (): video_file = open ( 'video_times.txt')    list = [] for line in video_file: run_time = float(line) list.append (run_time) print ('Video #', ':', run_time) print(list) sum = 0 for i in range(len(list)): sum = sum + list[i]    video_file.close main ( ) The following text is read from the video_times.txt file: Video # 1 : 10.0 Video # 2 : 24.5 Video # 3 : 12.2 Video # 4 :...

  • Without using lambda in PYTHON How can I find the word "Code" and "code" on a website and print how many times they appear?

    Without using lambda in PYTHON How can I find the word "Code" and "code" on a website and print how many times they appear?

  • If I have a function in python, say show(B), how would I code it so that...

    If I have a function in python, say show(B), how would I code it so that if B is a list like [3,3,4,0,0,8,2,0,0,5], it should return the elements in B that are not in range(len(B)). So the length of B in the given example is 10 so the range is from 0 to 9, so we want to return [0,1,2,5,6,9] since these are the values not in B. Thanks

  • Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that...

    Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that calls this function and uses keyword arguments to pass ‘testing’ into x and 2 into y. b. What will be printed when the function call executes? 6. Write a statement that generates a random number in the range I'm using python to solve this this is what i did def main():      result= my_function(x='testing', y=2)      print(result) def my_function(x,y):      return x[y] main()

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT