python - Apply formula with two different lists -
i have 2 lists this:
lista = [51, 988, 1336, 2067, 1857, 3160] listb = [1, 2, 3, 4, 5, 6]
i have apply formula in lists:
n / pi * ((x*0.1)+1)**2 - pi * (x*0.1)**2
the 'n' elements of lista, 'x' elements correspond same index of 'n' in listb.
i need apply formula elements in both list. when loop runs first time needs this:
51/pi*((1*0.1)+1)**2 - pi *(1*0.1)**2
for second this, needs this:
988/pi*((2*0.1)+1)**2 - pi*(2*0.1)**2
and repeats until end of both lists.
i know have use 'for' loop, problem don't know how elements second list. i'm trying this:
for n in lista: n/pi*((......))
inside thhe brackets should elements listb don't know how them, , need have same index element lista. output should third list result of each formula applied.
i have tried explained myself best way possible, if don't understand question feel free ask question.
thanks in advance.
i assume both lists have same size time, pythonic way use lambda , list comprehensions:
lista = [51, 988, 1336, 2067, 1857, 3160] listb = [1, 2, 3, 4, 5, 6] math import pi formula = lambda n,x: n / pi * ((x*0.1)+1)**2 - pi * (x*0.1)**2 res = [ formula(a,b) a,b in zip(lista,listb) ] >> [19.621466242038217, 452.96994140127384, 718.7747248407644, 1289.7268993630569, 1329.8678662420382, 2575.175332484077]
Comments
Post a Comment