[Tutor] (no subject)

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jan 29 19:30:37 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.


First, the indentation is all gone, pleae make sure you 
post using plain text so that indentation is preserved. 
I know thats not always esy depending on the mail tool 
but it helps a lot with Python!

> ### the code
> print '----newKeyRS'
> newKeyRS = []
> for newRecord in newRS:

newRS isn't defined yet...

> newPk = ''
> for nKey in newKeys:

Neither is newKeys...

    > newPk = newPk + str(newRecord[nKey]).strip()

Without any idea of what newRecord or newKeys looks like its 
hard to know if this is right or not, assuming it is...

    > newKeyRS.append((newPk, newRecord))
    > if newPk[:5]=='15000': 
         print (newPk, newRecord)
 
> print '        ----'

Is this supposed to be inside the if?
Or even inside the loop?


> 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})

So what did you expect? What came out looks like what 
you put in assuming that the dictionary is what 
newRecord looked like originally.

What exactly do you perceive to be the problem? I 
assume its the fact that only the even numbers 
are printing in the second set? I don;t know why 
thats happening because I'm not exactly sure whats 
happening in the section above.


Alan G.



More information about the Tutor mailing list