Skip to content
Advertisement

How to use i right in a for loop?

I have 3 lists and I need to calculate for each i the product of first list i, second list i and third list len-(i+1).

I tried to make a for loop which will do it for each i and I wrote this

JavaScript

But it says in the second line “‘type’ object is not iterable” How can I make it work?

Advertisement

Answer

Here you would need to get a little fancy and use the zip() function to properly iterate over all the members of the list.

here is some information on it: https://www.geeksforgeeks.org/python-iterate-multiple-lists-simultaneously/

JavaScript

Output: 15, 32.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement