Re: [Tutor] Problem with nested for-in (Alan Gauld)

2009-01-29 Thread Kent Johnson
On Thu, Jan 29, 2009 at 12:21 PM, emmanuel.delaborde wrote: > On 29 Jan 2009, at 15:26, Kent Johnson wrote: >> What are you trying to do? Generally problems of the form >> for item in list1: >> if item in list2: >> # do something with item >> > > the first csv file is a list of rows like this

Re: [Tutor] Problem with nested for-in

2009-01-29 Thread spir
Le Thu, 29 Jan 2009 11:06:57 +, "emmanuel.delaborde" a écrit : > 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: > stories = [] > for line2 in lin

Re: [Tutor] Problem with nested for-in (Alan Gauld)

2009-01-29 Thread Kent Johnson
On Thu, Jan 29, 2009 at 8:55 AM, emmanuel.delaborde wrote: >> >> I suspect that you need to reset the reader iterator to the start. >> I'm sure there will be something in the iterator protocol to do >> that No, in general iterators cannot be reset. >> but failing that you would need to change th

Re: [Tutor] Problem with nested for-in (Alan Gauld)

2009-01-29 Thread emmanuel.delaborde
I suspect that you need to reset the reader iterator to the start. I'm sure there will be something in the iterator protocol to do that but failing that you would need to change the inner loop to: for line2 in csv.reader(open("CATEGORYLIST.csv","r")) which will re-read the file and create a new

Re: [Tutor] Problem with nested for-in

2009-01-29 Thread Alan Gauld
"emmanuel.delaborde" wrote 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: stories = [] for line2 in lines2: if line2[1] == line[0]: stories.append(line2

Re: [Tutor] Problem with nested for-in

2009-01-29 Thread W W
On Thu, Jan 29, 2009 at 5:06 AM, emmanuel.delaborde < emmanuel.delabo...@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 > >

[Tutor] Problem with nested for-in

2009-01-29 Thread emmanuel.delaborde
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: stories = [] for line2 in lines2: if line2[1] == line[0]: stories.append(line2[0]) old_cats.appen