Below:
(link for link in get_links(html) if (link_regex, link)) # The above statements are written separately, as follows. # But the following needs to be used, and if it's still used it will give the wrong result for link in get_links(html): if (link_regex, link): (link)
Let's experiment with ipython.
As you can see from the above figure, for in if hit derivation implicitly transforms the link from str to list, and writing it separately won't convert it for us, so we need to use append to add the whole str to the list.
Addendum: python's for i in list traps
d = [1,2,3,4,5] for i in d: (i) print d
The result is :
[2, 4]
This trap is more hidden, when I test with white box again, I found this bug, the general reason is that after remove d[0], i automatically becomes d[1], but d has become d[2,3,4,5], so i=d[1] is pointing to 3 sadly, skipping 2!
Looks like python still needs to pay attention to understanding the underlying implementation!
The solution.
d = [1,2,3,4,5] for i in d[:]: (i) print d
It is possible to delete while traversing
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to give me advice.