-3

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]
Fxs7576
  • 1,259
  • 4
  • 23
  • 31

4 Answers4

3

Use this code:

x = 100
for item in range(x):
    print(list(indicator.values())[item])]
Peter234
  • 1,052
  • 7
  • 24
0

Use range() with for to iterate it from 0 to 100. For example:

for i in range(100):
    print i
# prints number from 1 to 100 
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
0

read this document

and try this code

x = range(0,100)

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

For -- in -- is python's way of iterating (going through) something iterable (something that can be gone through). For example a list and a dictionary are iterable. The range function creates a list with given parameters, making an integer (which is not itself iterable) iterable.

Josiah Coad
  • 325
  • 4
  • 11