[Tutor] Re: Unexpected results with list
Lee Harr
missive at hotmail.com
Thu Jan 29 17:11:31 EST 2004
>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)
I think I might write this as newPk.startswith('15000')
>
>print ' ----'
>for newRecord in newKeyRS:
> if newRecord[0][:5]=='15000': print newRecord
How about changing this to ...
for newPk, newRecord in newKeyRS:
if newPk.startswith('15000'):
print (newPk, newRecord)
else:
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})
It would be very helpful to have a full working example to
play with...
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the Tutor
mailing list