[Tutor] A replacement for a "for" loop
Scott Oertel
freebsd at scottevil.com
Wed Aug 29 18:34:27 CEST 2007
John Fouhy wrote:
> On 29/08/07, Trey Keown <trey at opmstech.org> wrote:
>
>> 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?
>>
>
> for key in keys:
> print 'Attribute %s has value %s' % (key, attrs[key])
>
>
Why even have the keys variable at all..
for key in attrs:
print 'Attribute %s has value %s' % (key, attrs[key])
-Scott Oertel
More information about the Tutor
mailing list