How to apply a function to each element of a list without for loops or lambda functions?

Question:

For example, let’s say I have a list:

integer_list = [1, 2, 3, 4]

and I want to plug each element of the list into a formula, like (x*5)+1. Right now I am doing integer_list[0] * 5 + 1 How would I then get the answer from that and multiply every item in the set by it?

Please help!

Asked By: kamilla

||

Answers:

no lambda no cry

def f(x):
    return (x*5)+1

result = list(map(f, integer_list))
Answered By: Kelly Bundy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.