List comprehension:
-> List comprehension is a concise way to create new lists by applying an expression to each item in an existing iterable, like a list, tuple or range.
-> Example:
l = [no*no for no in range(1,11)]
print(l)
Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
WHY List Comprehension:
1) Concise Code
2) Readability
3) Efficiency: (better than normal for loops - Optimized code)
Top comments (0)