#---------------------------------------------- # PROBLEM 2 #---------------------------------------------- # # Download the file db.csv from: # http://www.samyzaf.com/braude/PYTHON/projects/db.csv # Write a function db_query(file) for finding all the persons that meet the following criteria: # - They are from Florida or California # - Have blood type B+ or O+ # - Own a Mazda car # - Were born before 1982 # - How many such people did you find? def db_query(csvfile): f = file(csvfile, 'r') keys = f.next().strip().split(",") counter = 0 print memory_usage() for line in f: values = line.strip().split(",") d = dict(zip(keys, values)) if (d['State'] == 'CA' or d['State'] == 'FL') and \ (d['BloodType'] in ['B+', 'O+']) and \ 'Mazda' in d['Vehicle'] and \ int(d['Birthday'][-4:]) < 1982: #print d['GivenName'], d['Surname'] counter += 1 f.close() print memory_usage() print counter if __name__ == '__main__': db_query("D:/workspace/db.csv")