Oct-01-2016, 06:07 PM
Hello,
I've recently discovered List Comprehensions - which, for the project I am working on, are awesome.
I'm having to create lists based on other content that gets 'filtered' with for loops / if statements.
A lot of people mention List Comprehensions being 'easier to read'.
Honestly, I think the feature is cool, but I much prefer the readability of the old fashioned way - actually nesting this stuff inside of their for loops / if statements.
For some reason, having everything broken down like that is just easier for me to follow and understand what the program is doing.
So -
A) Though both yield the same result, is one way faster than the other?
If in fact they take the same amount of time to process, then what is the benefit of doing the comprehension - just the 'readability'?
B) In the 'real world' of using Python - is it frowned upon to build lists not using the list comprehension feature (assuming execution time is the same)?
At first glance, this seems like a Personal Preference vs Actual Performance battle.
I've recently discovered List Comprehensions - which, for the project I am working on, are awesome.
I'm having to create lists based on other content that gets 'filtered' with for loops / if statements.
A lot of people mention List Comprehensions being 'easier to read'.
Honestly, I think the feature is cool, but I much prefer the readability of the old fashioned way - actually nesting this stuff inside of their for loops / if statements.
For some reason, having everything broken down like that is just easier for me to follow and understand what the program is doing.
So -
A) Though both yield the same result, is one way faster than the other?
If in fact they take the same amount of time to process, then what is the benefit of doing the comprehension - just the 'readability'?
B) In the 'real world' of using Python - is it frowned upon to build lists not using the list comprehension feature (assuming execution time is the same)?
At first glance, this seems like a Personal Preference vs Actual Performance battle.