Skip to content

Commit

Permalink
feat: Add list comprehension in list tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
varian97 authored and Akuli committed Jul 25, 2020
1 parent 7e732f7 commit 52073d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions basics/lists-and-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ 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.

```python
>>> numbers = [1,2,3,4,5]
>>> numbers_squared = [ number ** 2 for number in numbers ]
>>> numbers_squared
[1, 4, 9, 16, 25]
>>>
```

We can also use slicing and indexing to change the content:

```python
Expand Down

0 comments on commit 52073d8

Please sign in to comment.