import csv import gzip from collections import defaultdict with gzip o

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import csv
import gzip
from collections import defaultdict
with gzip.open('rnd.gender') as f:
reader = csv.reader(f, delimiter='\t')
rnd = dict(list(reader))
with open('live.gender') as f:
render = csv.reader(f, delimiter='\t')
live = dict(list(render))
common = set(live) & set(rnd)
counts = defaultdict(int)
for x in common:
key = '=' if live[x] == rnd[x] else '!='
counts[key] += 1
print 'Acc:', counts['='] / float(len(common))