Fastest way to count combinations of values from two lists/arrays I have a file with mostly 0 and 1. For each line I would like to compare it against all others (without the redundancy) and count the different combinations. It is slightly more complicated as there are also "N" in the matrix when there is missing data. For example if the two lines are:

line1 = "0 0 1 0 1"
line2 = "0 1 1 0 1"


Then I would like to create a two by two table like this:

    0   1 
 0| 2 | 1 |
 1| 0 | 2 |


At the moment I am doing something like this:

line1_list = line1.split()
line2_list = line2.split()


To get the counts I have tried two options. The first if using a for loop:

tab_dict = defaultdict(int)
for i in xrange(0,len(line1_list)):
    key = line1_list[i]+"-"+line2_list[i]
    tab_dict[key] += 1


And the second is using a combination of map and zip:

tab_dict = Counter(map(lambda x:x[0]+"-"+x[1],zip(line1_list,line2_list)))


The first option seems to be the fastest but I was wondering if there is a faster way because the matrix I have is very big and it will take a long time to run. I have tried to look for libraries to do this but have not found anything yet.
I would drop construction of string and just do:

from itertools import izip

line1 = "0 0 1 0 1"
line2 = "0 1 1 0 1"

line1_list = line1.split()
line2_list = line2.split()

tab_dict = Counter(izip(line1_list, line2_list))


construction of tuple if faster than string, you remove unneeded operation, and making a table from a tuple of two if pretty much the same as making it from a complex string key, I would say that making it out of tuple of (x,y) is more logical.