newbie - again ! iterating through two nested lists?

eif eif at ukonline.co.uk
Sat Sep 1 20:26:38 EDT 2001


thanks for the help before guys - what im trying to do now is iterate
through two nested lists - im trying to compare the third element of each
list and if they are equal then I want to append this element plus some of
the other element s into a new list this is what ive got so far:


#!/usr/local/bin/python



import string
listedRecs1 = [rec.split('|') for rec in open('lecturer.txt').xreadlines()]
listedRecs2 = [rec.split('|') for rec in open('exam.txt').xreadlines()]
intersection = []
disjunction = []
x=0
z=0

for line in listedRecs1[x]:
    if line in listedRecs2[z]:
        intersection.append(line)
    else:
        disjunction.append(line)
    x= x+1



print intersection

the output is: ['', '016354']
so its comparing the first in each - but can anyone help me to do the
others?
plese help its the early hours and my head is hurting

these are the two lists:

listedRecs1
[['999347857', '', '9/1/2001 at 13:37:37', '016354', 'jim o shea',
'jim at mmu.ac.uk', '126', '0161025658\n'], ['999347943', '', '9/1/2001 at
13:39:03', '223654', 'roy saberton', 'roy at mmu.ac.uk', '201',
'0161236510\n'], ['999347943', '', '9/1/2001 at 13:39:03', '223654', 'roy
saberton', 'roy at mmu.ac.uk', '201', '0161236510\n']]

listedRecs2
[['999369265', '', '9/1/2001 at 19:34:25', '016354', 'maths', '2.00',
'30.6.01', '9.00am\n'], ['999369338', '', '9/1/2001 at 19:35:38', '223654',
'english', '1.30', '31.06.01', '1.30\n'], ['999369367', '', '9/1/2001 at
19:36:07', '568796', 'welsh', '3.00', '01.07.01', '1.30\n']]






More information about the Python-list mailing list