Oct-09-2017, 09:40 PM
This reply speaks to your understanding of list comprehensions, so that you might understand the code,
and see there is probably no need to convert it.
This code:
executes more efficiently than the corresponding for loops. If the original code works,
and you change it, you risk breaking it without being able to fix it.
and see there is probably no need to convert it.
This code:
text = [y.text for x in player_data for y in x.descendants if y.name == 'div']is equivalent to:
text = [] for x in player_data: for y in x.descendants: if y.name == 'div': text += [y.text]As you can see the list comprehension is more concise, and, according to python developers,
executes more efficiently than the corresponding for loops. If the original code works,
and you change it, you risk breaking it without being able to fix it.