[Tutor] Unexpected results with list

Michael Long mlong at datalong.com
Thu Jan 29 13:20:14 EST 2004


Hi,

I cannot see the flaw in the logic of my code. I would appreciate it if someone
could explain the results I am seeing.

### the code
print '----newKeyRS'
newKeyRS = []
for newRecord in newRS:
        newPk = ''
        for nKey in newKeys:
                newPk = newPk + str(newRecord[nKey]).strip()
        newKeyRS.append((newPk, newRecord))
        if newPk[:5]=='15000': print (newPk, newRecord)

print '        ----'
for newRecord in newKeyRS:
        if newRecord[0][:5]=='15000': print newRecord

### the results
----newKeyRS
('150002', {'GroupCode': 50002, 'LanguageId': 1})
('150003', {'GroupCode': 50003, 'LanguageId': 1})
('150004', {'GroupCode': 50004, 'LanguageId': 1})
('150005', {'GroupCode': 50005, 'LanguageId': 1})
('150006', {'GroupCode': 50006, 'LanguageId': 1})
('150007', {'GroupCode': 50007, 'LanguageId': 1})
('150008', {'GroupCode': 50008, 'LanguageId': 1})
('150009', {'GroupCode': 50009, 'LanguageId': 1})
        ----
('150002', {'GroupCode': 50002, 'LanguageId': 1})
('150004', {'GroupCode': 50004, 'LanguageId': 1})
('150006', {'GroupCode': 50006, 'LanguageId': 1})
('150008', {'GroupCode': 50008, 'LanguageId': 1})

Thanks,
Mike





More information about the Tutor mailing list