im using python within grasshopper to construct komplex geometrical shapes, therefore i often work with lists and loops. I need to operate one list element with another, the next one in the same list, for instance. Does anyone have an alternative solution for my cause?
Cheers, Julian
So the way i figuered out, is to duplicate the list an shift/offset the elements in the list. (see in script below) I'm curious about an easier way, due to the number of lists in my scripts. Here's a little example.
TestList = [0,1,2,3,4,5]
TestList2 = TestList[-1:] + TestList [:-1]
TestList3 = []
for i, ii in zip(TestList,TestList2):
TestList3.append(i + ii)
print(TestList3)
TestList3 = [5,1,3,5,7,9]
If you do this a lot, I would make a method out of it, then you can make the implementation as verbose as you like and keep the use clean:
or
To clean it up a bit I might be tempted to yield the results like:
or even:
Alternatively, if you don't like the method approach and just wanted something compact, I would go with:
Without getting too golfy, you technically don't need the dedicated variable and you should be able to do: