Monday, April 16, 2012

Loop in two lists

I have these lists:



list1 = [3, 5, 2, 1, 9]
list2 = [6, 9, 1, 2, 4]
list3 = []
list4 = []


and I want to pass these formula:



x = a/b
y = 1/b


in which a is every value in list1 and b is every value in list2 and append the result of calculations into two empty lists - list3 and list4.



This is what I have but it's a disaster haha :(



u = 0
while u<len(list1):
for a in list1:
for b in list2:
x = a/b
y = 1/b
u+=1
list3.append(x,)
list4.append(y,)


Anyone can help me with this?





No comments:

Post a Comment