Fxs7576 Fxs7576 - 3 months ago 12
Python Question

For Loop at Python

My goal is to create a for-loop code that will return an output like the following:

list(indicator.values())[0],
list(indicator.values())[1],
list(indicator.values())[2],
list(indicator.values())[3],
...
...
list(indicator.values())[98],
list(indicator.values())[99],


However when I run the code below, I receive an error message 'TypeError: 'int' object is not iterable'. How can I fix this so I can get the intended result?

x = 100
for item in x:
list(indicator.values())[item]

Answer

Use this code:

x = 100
for item in range(x):
    print(list(indicator.values())[item])]