I'm not quite sure what you're asking, but if you want to print each row that contains any of the numbers in affiliate_phone_dict
, this will do:
lookup = {'name1': 'xxx-xxx-xxxx',
'name2': 'yyy-yyy-yyyy'}
with open('data.csv') as data_file, open('out.csv', 'w') as out_file:
for row in data_file:
if any(num in row for num in lookup.values()):
out_file.write(row)
data.csv
Date Time Length Cost Bill Category Destination Number Destination City Origin Number OriginCity
01/01/0001 10:37 3 $0.00 LOCAL AIRTIME, LONG DISTANCE and INTERNATIONAL CHARGES xxx-xxx-xxxx City Name aaa-aaa-aaaa City Name Mobile
01/01/0001 10:37 10 $0.00 LOCAL AIRTIME, LONG DISTANCE and INTERNATIONAL CHARGES yyy-yyy-yyyy City Name zzz-zzz-zzzz City Name Mobile
01/01/0001 10:37 10 $0.00 LOCAL AIRTIME, LONG DISTANCE and INTERNATIONAL CHARGES 123-456-7890 City Name zzz-zzz-zzzz City Name Mobile
out.csv
01/01/0001 10:37 3 $0.00 LOCAL AIRTIME, LONG DISTANCE and INTERNATIONAL CHARGES xxx-xxx-xxxx City Name aaa-aaa-aaaa City Name Mobile
01/01/0001 10:37 10 $0.00 LOCAL AIRTIME, LONG DISTANCE and INTERNATIONAL CHARGES yyy-yyy-yyyy City Name zzz-zzz-zzzz City Name Mobile