|
|
|
|
|
by pansa2
2249 days ago
|
|
Python’s list comprehension syntax is based on the set-builder notation from mathematics. However, I think it would have been better to break with tradition and use a different order, one which matches the order of the equivalent nested loops: flattened_list = [for x in list_of_lists: for y in x: y]
This is essentially the same re-arrangement that was made in C#‘s LINQ: it uses from-where-select instead of SQL’s select-from-where. |
|
I prefer it as a sequence of steps that get performed one after the other like a pipeline.