Use list of integer type in a loop in python
<p>I have the following code:</p>

<pre><code>a=[]
b=[]

for s in range(10):   
    dw = s%5
    if dw == 1: 
        WD = random.randint(60,100) 
        DD =[int(round(dc*WD,0)) for dc in [.2,.2,.2,.2,.2]]
        for k in range(5):
            a.append(DD[k])
        print a    
    TCV = DD[dw]
    DDPT = [int(round(pt*TCV)) for pt in [.3,.5,.2]]
    for i in range(3):
        b.append(DDPT[i])
    for PT in range(3):
        for p in DDPT[PT]:
            print 't'
</code></pre>

<p>After running the code I get this error:</p>

<pre><code>for p in DDPT[PT]:

TypeError: 'int' object is not iterable.
</code></pre>

<p>I was wondering if someone can help me in this regard.</p>

<p>Thanks!</p>

<p><code>DDPT</code> is an array of integers, as evidenced in this line:</p>

<p><code>DDPT = [int(round(pt*TCV)) for pt in [.3,.5,.2]]</code></p>

<p><code>DDPT[PT]</code> is some integer, and you are trying to iterate through that. Hence the error.</p>

<p>I would recommend giving your variables more descriptive names so these issues are easier to debug.</p>

<p>edit:</p>

<p><code>for num_iters in DDPT:
    for iteration in range(num_iters):
        do_something()
</code></p>

python