[Tutor] Searching for items in two lists.
Doug.Shawhan@gecits.ge.com
Doug.Shawhan@gecits.ge.com
Wed, 20 Mar 2002 10:41:25 -0500
Quoth Alan:
>> >>> l='freep, creeep, jeep'
>> >>> foop=l.split(',')
>Here you split it into words.
Yes, I was just lazily splitting a string into a list, cause I wanted to
avoid typing quotes! :-)
>> #open 600k file to look in
>> f2=open("\\tmp\\new.csv",'r')
>> lookin=f2.readlines()
>But here you don't split even tho' it hints that its
>a CSV file...
Yep, each line in the file represents an entry, so I don't need to split
them.
>> for item in lookfor:
>> for searched_string in lookin:
>So you are searching the full line of entries
>not just the single items - is that what you want?
Yes indeed!
>> else: answers.append(searched_string)
>And appending the whole line not just an entry...
Right!
>> I must have a flaw in my logic somewhere, cause my output
>> file is on the order of 15 megs!
>If you only appended single entries would it look more sane?
The format of the two files is like so:
lookfor:
123456
a12345
b12345
c12345
lookin:
"'Briggs', 'Joebob'", 'my house', '12345', 'Yadda yadda'
"'Briggs', 'Joejim'", 'Guy house', '12222', 'Fu-Bar'
"'Briggs', 'Joeweasel'", 'Thai house', 'b3214', 'Foo Bar'
"'Briggs', 'Joeblow'", 'thy house', 'c5588', 'Yadda yammar'
For each line in lookfor I want to search each line in lookin and return the
entire line to a list and thereby to a file. For some reason, I seem to be
finding more than my share of items.... several times! :-)
>Alan G