diff --git a/basics/lists-and-tuples.md b/basics/lists-and-tuples.md index 2bb4dff..41f7ad9 100644 --- a/basics/lists-and-tuples.md +++ b/basics/lists-and-tuples.md @@ -142,7 +142,7 @@ We'll talk more about loops [in the next chapter](loops.md). ``` Another useful things about list is **comprehension**. -**Comprehension** is a way to loop the list in single line. It makes our code more pythonic. +**Comprehension** is a way to construct a list in single line. It makes our code more clean, shorter and easier to read. ```python >>> numbers = [1,2,3,4,5] @@ -152,6 +152,18 @@ Another useful things about list is **comprehension**. >>> ``` +without comprehension: + +```python +>>> numbers = [1,2,3,4,5] +>>> numbers_squared = [] +>>> for number in numbers: +... numbers_squared.append(number**2) +>>> numbers_squared +[1, 4, 9, 16, 25] +>>> +``` + We can also use slicing and indexing to change the content: ```python