[Tutor] Problem with nested for-in
W W
srilyk at gmail.com
Thu Jan 29 12:43:37 CET 2009
On Thu, Jan 29, 2009 at 5:06 AM, emmanuel.delaborde <
emmanuel.delaborde at cimex.com> wrote:
> Hello,
>
> I have the following snippet :
>
> lines = csv.reader(open("CATEGORY.csv","r"))
> lines2 = csv.reader(open("CATEGORYLIST.csv","r"))
>
> old_cats = []
> for line in lines:
print line
>
> stories = []
> for line2 in lines2:
print line2
>
> if line2[1] == line[0]:
> stories.append(line2[0])
> old_cats.append((line[0],line[2], stories))
>
>
> what happens is that
>
> for the first elt of lines, the nested for in runs fine
> but then never seem to run again while the top level loop iterates through
> the rest of lines
>
> consequently stories accumulate nothing...
>
> Can someone explain please ?
>
I would try adding the two print statements above to your code. It might
give you an idea about what's going on. It would also be helpful to provide
us with some of your original data and the data you get once you've run the
program.
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090129/60e6290d/attachment.htm>
More information about the Tutor
mailing list