I'm starting to work and getting more familiar with Python in the context of data analytics and just got to know about list comprehensions which I find really elegant.
Although I'm aware there ist the risk of falling into love with it too much at the cost of readabilty, I really didn't find any guidelines or rules of thumb of when or when not to use it.
In my own code I used this generator expression inside a recursive function --> find_children() is a user definded function to create hierarchical data
(find_children(ancestor) for ancestor in parents if len(parents) > 0)
instead of
if len(parents) > 0:
for ancestor in parents:
find_children(ancestor)
It looks more neat but that's actually the only reason for me.
So I would like to collect opinions of maybe some experienced Pythonistas and their approach regarding this or what best practice is.