Repeating a for in line loop python
<p>How would I repeat this (excluding the opening of the file and the setting of the variables)?
this is my code in python3    </p>

<pre><code>file = ('file.csv','r')
 count = 0 #counts number of times i was equal to 1
 i = 0 #column number 
 for line in file:
    line = line.split(",")     
    if line[i] == 1:
        count = count + 1
 i = i+1
</code></pre>

<p>If I understand the question, try this and adjust for however you want to format. Replace <code>NUM_COLUMNS</code> with the number of times you want it repeating</p>



<pre><code>file = open('file.csv','r')
data = file.readlines()
for i in range(NUM_COLUMNS): 
    count = 0
    for line in data:
        line = line.split(",")

        if line[i] == ("1"):
            count = count + 1
    print count
</code></pre>



python list python-3.x csv repeat