# Comprehensions
When creating a [[list]], a [[dict]], or a [[set]], we often encounter this kind of code:
```python
students = []
for grade in all_grades:
students.append(grade['student'])
```
This is a very common and recognizable [[Patterns of Python|pattern]] that can and should be changed to a [[ListComp - List Comprehension|list comprehension]]:
```python
students = [grade['student'] for grade in all_grades]
```
This have multiple benefits:
- Concise and readable: The entire process of looping and building the [[list]] is expressed in a single line that looks like natural langage: "Students is a [[list]] of students from grade for each grade in the [[list]] of all grades."
- Improved performance: The [[list]] is not created empty and filled many times afterward, which would require many [[Allocation|reallocation]] of [[memory]].
---
Bibliography:
- [Title - website.com](need bibliography)