[Tutor] problem with csv dictreader
Eduardo Vieira
eduardo.susan at gmail.com
Mon Jul 27 18:35:08 CEST 2009
Hello, I'm enjoying learning python but then I come across some basic
things that makes me stumped... I have 2 csv files and I want to see
which ones are duplicates based on two criteria email, or telephone.
The order of fields in both csv files are different. Here are a sample
bogus data:
import csv
bv = """NAME,BVADDRTELNO1,BVADDREMAIL
Company1, 1234567788, this at that.com
CompanyA, 1231234455, that at this.com
CompanyC, 1011011111, new at this.com
CompanyD, 2222222222, old at olde.com
"""
site = """Company,Email,Phone
"Company3","nothing at nada.com","1234560000"
"CompanyD","old at olde.com","2222222222"
"Company1","this at that.com","1234567788"
"""
bv = bv.upper() # This is just to make the data more homogeneous and
detect duplicates more easily
site = site.upper()
bvreader = csv.DictReader(bv.splitlines(True))
sitelist = csv.DictReader(site.splitlines(True))
for row in sitelist:
for line in bvreader:
if row['EMAIL'] == line['BVADDREMAIL']:
print line['NAME'], row['COMPANY']
#=====
My questions are:
Why nothing is being printed? Two rows should be printed right?
What would be better for the outer loop, the bigger list or the small
list? The biglist (bvreader) is under 2100 lines (244Kb) and the
smaller list (sitelist) can be 20 lines or less.
Thanks.
Eduardo
More information about the Tutor
mailing list