Note that there are some explanatory texts on larger screens.

plurals
  1. POPython row.count error
    primarykey
    data
    text
    <p>I am very new to python and have no idea what I'm doing but I am trying to learn as I program as this is what I have done in the past with C, C++, and Cocoa. </p> <p>I am writing a program with a matrix. I want to count the number of occurrences of x (x being a value in my matrix.) When I try to do this though I am not exactly sure what I am getting. A nice explanation of what I am getting and how to do things with matrices is all I am looking for. Eventually I will want to use the matrix.insert, the matrix.tofile, and the matrix.remove commands as well. Any sort of help is appreciated. </p> <p>Here is my Code:</p> <pre><code> matrix = [ [2, 9, 7, 5, 8, 9, 2, 4, 6], [8, 1, 1, 8, 4, 7, 5, 1, 3], [5, 5, 7, 7, 9, 3, 8, 1, 5], [1, 7, 8, 8, 2, 6, 4, 5, 9], [3, 8, 6, 3, 1, 7, 4, 9, 6], [9, 5, 4, 5, 9, 4, 2, 2, 3], [1, 2, 5, 9, 7, 9, 6, 1, 1], [7, 5, 8, 3, 2, 6, 9, 1, 5], [3, 1, 9, 6, 7, 8, 5, 3, 4], ] for sublist in matrix: S = str(sublist) print (S) for row in matrix: A = row.count(0) B = row.count(1) C = row.count(2) D = row.count(3) E = row.count(4) F = row.count(5) G = row.count(6) H = row.count(7) I = row.count(8) J = row.count(9) print (A) for row in matrix: if A &gt; 0: if B &lt; 1: print (B) </code></pre> <p>Here is what I get when I run the program:</p> <pre><code>[2, 9, 7, 5, 8, 9, 2, 4, 6] [8, 1, 1, 8, 4, 7, 5, 1, 3] [5, 5, 7, 7, 9, 3, 8, 1, 5] [1, 7, 8, 8, 2, 6, 4, 5, 9] [3, 8, 6, 3, 1, 7, 4, 9, 6] [9, 5, 4, 5, 9, 4, 2, 2, 3] [1, 2, 5, 9, 7, 9, 6, 1, 1] [7, 5, 8, 3, 2, 6, 9, 1, 5] [3, 1, 9, 6, 7, 8, 5, 3, 4] 0 0 0 0 0 0 0 0 0 </code></pre> <p>Thank You!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload