CBSE Class 12 Computer Science
Question 37 of 68
Data Structures - I : Linear Lists — Question 9
Back to all questionsAdvantages of list comprehensions are as follows:
- Code reduction — A code of 3 or more lines (for loop with or without a condition) gets reduced to a single line of code.
- Faster code processing — List comprehensions are executed faster than their equivalent for loops for these two reasons:
- Python will allocate the list's memory first, before adding the elements to it, instead of having to resize on runtime.
- Also, calls to append() function get avoided, reducing function overhead time (i.e., additional time taken to call and return from a function).