[Tutor] Unexpected results with list
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Jan 29 19:41:36 EST 2004
OK, Thats better, I can see the structure this time,
although I still don't see the missing data definitions...
> ### the code
> print '----newKeyRS'
> newKeyRS = []
> for newRecord in newRS:
> newPk = ''
> for nKey in newKeys:
> newPk = newPk + str(newRecord[nKey]).strip()
This strikes me as strange since you just keep appending to newPk.
You never reset it. Presumably newKeys is a list of numbers?
But then every time through the newRecord loop you get the same
newPk value since you never change newKeys?
> newKeyRS.append((newPk, newRecord))
But from the output below you are patently getting different
newPk values... hmm.
> if newPk[:5]=='15000': print (newPk, newRecord)
And since the original record is the second element we must
assume that the nKey loop extracts the GroupCode value from
the dictionary by treating the dictionary as a string?
But how does it prepend the 1 that we see in the newPk
values?
I think I'm missing something somewhere?
> 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})
...
> ----
> ('150002', {'GroupCode': 50002, 'LanguageId': 1})
> ('150004', {'GroupCode': 50004, 'LanguageId': 1})
Confused,
Alan G
More information about the Tutor
mailing list