Hi! I am doing my first python course with Dr.chuck and it has been really interesting and joyful to learn new language. However, while I am following exercises I couldn’t understand this following example code .
The full version of code is in this link. I am not sure I can share whole code with copy and paste so I leave this link here.
http://www.py4e.com/code3/tracks.zip
The part I don’t get is
def lookup(d, key):
found = False
for child in d:
if found : return child.text
if child.tag == 'key' and child.text == key :
found = True
return None
This function. I don’t know why
if found : return child.text
is ahead of
if child.tag =='key' and child.text == key :
I’ve read a comment below of this youtube video, however I still didn’t get it. Maybe my English is not good enough to follow but I wonder if there’s anyone can help me to understand . Thank you in advance and If there’s any problem with this post for sharing code and materials , please let me know so I can fix this post or delete it.