How can I manipulate an array declared as `self.tab[('_',0)]` without explicitly knowing what it contains?
<p>I am writing a code in python that will be reading each character from a file and save its number of occurrences. As it is a homework assignement, I am not allowed to change the way the array was declared.</p>

<p>The array was declared in this way:</p>

<pre><code>    def __init__(self):
       self.tab = [('_', 0)] * 100
       self.size = 0 
</code></pre>

<p>Now, every time I read a character, I check wheter I already had noticed it or not:</p>

<pre><code>    def add(self, c): # c is the character that was read

    for i in range(0,self.size):
        if self.tab[i] == (c, ): # this is where my problem occurs. 
                                  #How should should I check if the 
                                  #character given as an argument is
                                  #present in the array I declared 
                                  #before?

            self.tab[i] = ?       #Here I want to add 1 to the number 
                                  #of occurrences of the character. 
                                  #How should I do it?
        else:
            pass
</code></pre>

<p>As I said in the question, I don't know what the character equals to and what is the number does the second column equals to. I want to be able to add 1 to the number of occurrences without knowing how many occurrences there was.</p>

<p>I don't expect an answer that will give me the exact solution to my particular situation. All I need is a set of rules and exemples on how to work in such cases. </p>

<p>To check if your character is already present in the tab, you can use something like:</p>

<pre><code>found_char = [arr_item for arr_item in self.tab if arr_item[0]==c]
</code></pre>

<p>and check the returned value:</p>

<pre><code>if found_char == []:
    # add a new entry in your tab using the self.size attribute.
else:
    # use self.tab.index(...) to find the corresponding tupple in self.tab and 
    # replace it by a modified one as tupple are immutable.
</code></pre>

python arrays