Joining n number of cilinders with a curve

Hello all,
I’m trying to modify thefollowing scriptwithout success.
What I’m trying to do is not to limit the bridge created to two objects but to use various number of objects and to bridge them.
I’ve tried splitting a list in groups by 2 for example Cyl1, Cyl2, Cyl3, Cyl4 grouping them to list by 2 [Cyl1, Cyl2] then [Cyl2, Cyl3] then [Cyl3, Cyl4] and [Cyl4, Cyl1] as soon as I do that I’m receiving errors that the loop is expecting two items.
If someone could explain or show how to solve this I will appreciate a lot.

Thank you.