# GH Python Double Loop Two Lists Simultaneously And Update Values With Function

Hello,

I’ve been trying to learn Python concerning this problem:

1. x is a list of floats that need to be changed through a function in multiple loops
2. x[i] need to be larger than y (which increases by y each time the full list x has looped). So if x[i] > y: or if x > y:
3. x[i] is changed to x[i] = i + ln2*Pi whereas i is the float value of x[i], l is the float value of l[i] (another list that is also given, and n is a constant that is given
4. y is increased and the loop starts again with updated list x
5. loop restarts until no items in x left that are > y
6. the final list will have updated values that will be processed further in Grasshopper.

Summary of all inputs:
x: list of floats
y: constant 0.25 (based on a slider) that increases after each full loop
n: constant 10 (based on a slider), stays the same throughout
l: list of floats (same list length as x)

I’ve been having issues with not being able to process the two lists x and l through the same loop while they also have floats. None of the following have worked for me:

1. Does not change the values of the original list and may require a new list each loop?
result =
for i, j in zip(x, l):
if i > y:
i = i + jn2*Pi
result.append(i)
else:
result.append(i)
result = x

2. Neither have worked because of float error message (Runtime error (TypeErrorException): can’t multiply sequence by non-int of type ‘float’). Enumerate also did not help me because I could not use x[i] to replace original values in list x anymore.

#for i in range(len(x)):
#for i, j in zip(range(len(x)), range(len(l))):
for i, j in zip(x, l):
if x[i] > y:
x[i] = i + ln2*Pi

print(x)

I’m taking my first steps in Python and have researched this for a while. While I think I understand what logically must happen, I have not been able to put this together in Python yet and would be thrilled to learn from your examples. Thanks for taking a look!

Best,
Martin

Hello Martin,

You look like you are on the right track. Can you share a GrassHopper file, say which line is causing the error, and paste your code in backticks as described here