Question: I am trying to model a bag of words. I am having some trouble incrementing the counter inside my dictionary when the word is found in my data (type series):

```
def build_voc(self, data):
        for document in data:
            for word in document.split(' '):
                if word in self.voc:
                    self.voc_ctr[word] = self.voc_ctr[word] + 1
                else:
                    self.voc.append(word)
                    self.voc_ctr = 1

```

I tried indexing it as well this way just to test where the error was:

```
self.voc_ctr[word][0] = self.voc_ctr[word][0] + 1

```

But it still gives me the same error at that line:

> 
> TypeError: 'int' object is not subscriptable
> 
> 
> 

Knowing that this is a function in the same class, where self.voc and self.voc\_ctr are defined:

```
class BV:
    def __init__(self):
        self.voc = []
        self.voc_ctr = {}

    def build_voc(self, data):
        for document in data:
            for word in document.split(' '):
                if word in self.voc:
                    self.voc_ctr[word] = self.voc_ctr[word] + 1
                else:
                    self.voc.append(word)
                    self.voc_ctr = 1

```

The error seems to say self.voc\_ctr is an int object, but I defined it as a list so I don't know where I went wrong.

Answer: 
In Java the operator "==" checks if the two operands reference to the same object. Do not use "==" with any objects including Strings. And note Java Strings are immutable. That mean all the operations with them don't modify them but create new objects.
This is happening because `b` is equal to `"abc" + def`, and `def` is equal to `"def"`. So, essentially, you are comparing `"abcdef"` with `"abcdef"` by using `abcdef == b`.

So, in conclusion, it will *not* print nothing, because `"abcdef" == "abcdef"` *always* evaluates to `true`.