Question: I have two arrays 

```
a = [ab,bc,cd]
b = [bc,ab,cd]

```

I want to compare each element of a with each element of b and then increase `counter += 1` if they match, else `counter -1` and display `counter` 

```
counter=0
for i in a:
 for j in b: 
   if a[i-1] == b[j-1]:
      counter = counter + 1
   elif a[i-1] != b[j-1]:
      counter = counter - 1
  print counter

```

I am getting weird results, I am new to programming and help is appreciated.

Sorry for copy paste error

Answer: 
you can use sets:

```
a = ['ab','bc','cd']
b = ['bc','ab','cd']

print(len(set(a).intersection(set(b))))

3

```
Just a short and fast alternative:

```
sum(2*b.count(x) - len(b) for x in a)

```