It’s just a shorter way of expressing a list
.
li = [row[index] for row in outer_list]
is equivalent to:
li = []
for row in outer_list:
li.append(row[index])
Once you get used to the syntax, it becomes a tidy way of creating list
s (and other iterables).
More Related Contents:
- How to frame two for loops in list comprehension python
- How to create the following lists with list comprehensions? [closed]
- How to append new line to the list
- How to make a flat list out of a list of lists?
- How to iterate through two lists in parallel?
- What does “list comprehension” and similar mean? How does it work and how can I use it?
- How to check if all elements of a list match a condition?
- Why is a list comprehension so much faster than appending to a list?
- Python’s most efficient way to choose longest string in list?
- How can I iterate through two lists in parallel?
- List comprehension vs generator expression’s weird timeit results?
- Nested For Loops Using List Comprehension
- Appending item to lists within a list comprehension
- How do I iterate through two lists in parallel?
- How to return a subset of a list that matches a condition [duplicate]
- Sort multidimensional array based on 2nd element of the subarray
- How to access the elements of a 2D array?
- Why does a for-loop with pop-method (or del statement) not iterate over all list elements [duplicate]
- list.extend and list comprehension [duplicate]
- Comprehension on a nested iterables?
- remove None value from a list without removing the 0 value
- How can I use list comprehensions to process a nested list?
- interleaving 2 lists of unequal lengths [duplicate]
- What is the meaning of list[:] in this code? [duplicate]
- How to sort a 2D list? [closed]
- sum each value in a list of tuples
- Duplicate elements in a list [duplicate]
- How can I turn a flat list into a 2D array in python?
- Optimal method to find the max of sublist items within list
- Skip elements on a condition based in a list comprehension in python