Use a Descriptive Identifier Name
This program suffers from a bad naming practice:
def find(p):
res = []
for e in p.els:
if e.n == "img":
res.append(e)
return res
Can you understand what it does? Most likely not.
Solution
Give a proper and descriptive name for identifiers:
def get_image_elements(html_page):
elements = []
for element in html_page.elements:
if element.name == "img":
elements.append(element)
return elements
Now we know that it looks for all image elements within an HTML page.
Takeaways
A good naming practice makes our program easier to understand.