python - 2 Nested for loops, 2 variables (1 from a csv) & Unexpected Results -


i've been puzzling on why loop won't generate expected results - 1 matching entry generates 'yes' output. can point out error? csv i'm importing has 7 columns & 17,000 rows. "alle" imported csv list with 4 elements - each of list of 6 elements. i'm using python2.7 & realize i'm opening more libraries need, new & didn't want remove break code before posting this.

"alle" elements like:

['danlaw inc',  'applications engineer',  'novi, mi', 'http://www.indeed.com/rc/clk?jk=e199589101464b99',  'novi',  'mi'] 

rows of csv file like:

['4318055', 'brownsville', 'la', 'brownsville, la', '32.48709', '-92.1543', '4317'] 

here's code:

import math import csv import urllib2 urllib2 import urlopen import json json import load  import requests pprint import pprint time import sleep  f = open(r'c:\users\****\*****\python\best city pop long lat data\uscities1000_trimmed_full_noheader.csv', "rb") csv_f1 = csv.reader(f)  in alle:     e in csv_f1:         if a[2] == e[3]:             print ('yes') 

i have confirmed both lists have matching entry (which city & state - "novi, mi"), when run code don't "yes" output. thoughts? thank you!

update:

here how i'm appending "alle" csv list variable think causing problem:

def splitter(element):     city,state=element.split(', ',1)     return city, state  #   >>>>>  assign variable input city  #cities = [] #location = []    e in alle:     if ', ' in e[2]:         city,state = splitter(e[2])         #location = [[city],[state]]         #e.append(location)         e.append(city)         e.append(state) 

ok, figured out. way reading data csv file list variable culprit - although don't know exact reason. however, below works:

alle=[]  open(r'c:\users\****\******\recruiting business\proximity project\alldailycijobs 26thjan10_12-30daysnoheader.csv', "r+b") f:     reader = csv.reader(f)     row in reader:         alle.append(row) 

this trying use before:

f = open(r'c:\users\****\******\recruiting business\proximity project\alldailycijobs 26thjan10_12-30daysnoheader.csv', "rb")  alle = csv.reader(f) 

Comments