[Tutor] Problems understanding control flow

Eduardo Vieira eduardo.susan at gmail.com
Thu Jul 30 23:47:27 CEST 2009


Hello, list.
I can't understand why the print statement is not printed with the
operator '==', but is printed when using 'in'.
Here's the code:
#===
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())

sitelist = csv.DictReader(site.splitlines())

bvreaderone = list(bvreader)

# this does not work:
for row in sitelist:
   for line in bvreaderone:
       if row['EMAIL'] == line['BVADDREMAIL']:
           print line['NAME'], row['COMPANY']

# but this does work:
for row in sitelist:
   for line in bvreaderone:
       if row['EMAIL'] in line['BVADDREMAIL']:
           print line['NAME'], row['COMPANY']

#==

Regards,

Eduardo


More information about the Tutor mailing list