Re: Nested loop not working
- From: Dave Angel <davea@xxxxxxxx>
- Date: Fri, 16 Jul 2010 11:29:23 -0400
Johann Spies wrote:
I am overlooking something stupid.Once you've read all the data from 'data' in the first inner loop, there's no more for the second keyword.
I have two files: one with keywords and another with data (one record per line).
I want to determine for each keyword which lines in the second file
contains that keyword.
The following code is not working. It loops through the second file
but only uses the first keyword in the first file.
# -*- coding: utf-8 -*-
keywords = open("sleutelwoorde",'r')
data = open("sarua_marine_sleutelwoorde.csv",'r')
remove_quotes = re.compile('"')
for sw in keywords:
for r in data:
swc = remove_quotes('',sw)[:-1]
if swc in r.lower():
print swc + ' ---> ' + r
What am I missing?
Easiest answer is to do something like:
just before the inner loop. That will (re)position to begin of hte 'data' file.
- Prev by Date: Re: [ANN] inflect.py: generate plurals, ordinals, numbers to words...
- Next by Date: Re: [ANN] inflect.py: generate plurals, ordinals, numbers to words...
- Previous by thread: Re: Nested loop not working
- Next by thread: Re: MySQL One More Again