Suppose I have 2 lists, for which the i-th element of the first lists corresponds to the i-th element of the second list. How can i iteratively apply elements from the 2 lists into a different function?
def GetLists(n):
List1 = []
List2 = []
n = int(input("how many terms: "))
for i in range(1,n):
val1 = float(input("what is val1: "))
val2 = float(input("what is the corresponding val2: "))
List1.append(val1)
List2.append(val2)
return List1, List2
def newfunc(ListA, ListB, var):
# take i-th elements from lists A and B where (a,b) are the i-th elements of A and B
# want output = sum(a * var ** b) for index in len(A) if len(A) == len(B)
What is the most pythonic way to do this? If possible, I would like to do so without importing external modules.
Edit: I checked other solutions. The "duplicate" answer requires importing modules; I was trying to do without. Also, I am trying to do an operation that returns an output rather than print values, which complicates the use of zip beyond the level shown in the duplicate answer.