[Tutor] Re: Unexpected results with list
Michael Long
mlong at datalong.com
Thu Jan 29 20:03:49 EST 2004
>>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)
>
>
> I think I might write this as newPk.startswith('15000')
That syntax is much more intuitive.
>
> It would be very helpful to have a full working example to
> play with...
>
The entire piece involves connecting to 2 diffent databases and retrieving
recordsets which are to be compared. This statement "if newPk[:5]=='15000'" is
present to filter the resultset printed for debugging purposes.
I have found the offending code but do not understand what is going on. When you
run the following snippet it only print '150003' and '150005'. I would be grateful
for an explaination of this behavior.
newKeyRS = ['150003', '150004', '150005', '150006', '15007', '15008']
for newRecord in newKeyRS:
if newRecord.startswith('15000'): print newRecord
newKeyRS.remove(newRecord)
More information about the Tutor
mailing list