[Tutor] A replacement for a "for" loop

Trey Keown trey at opmstech.org
Wed Aug 29 03:56:26 CEST 2007


Hello everybody.
I'm using a couple of "for" loops to help me in xml parsing using expat.
Unfortunately, though, I've found that using more than one of these in a
row, at least in my case, causes a redundancy error.
a snippet of my code (note that this is not the way I set the dictionaries)-

attrs={u'title': u'example window title', u'name': u'SELF', u'icon':
u'e.ico'}
keys = ['name','title','icon']
for (tag, val) in attrs.iteritems():
    for key in keys:
        print val

the first "for" tag causes the dictionary (attrs) to have its keys called
"tag" and its value called "val". The second "for" loop causes the
dictionary keys to be read in a certain order. How could I take away the
first "for" loop and replace it with something else to do the same general
function?
thanks for any help.
Trey



More information about the Tutor mailing list