Skip to content

Commit

Permalink
Added Flatten()
Browse files Browse the repository at this point in the history
  • Loading branch information
irpepper committed Sep 19, 2019
1 parent 03d6954 commit 643aaf3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions snippets/flatten.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: flatten
tags: list,intermediate
---

Flattens a list of lists.

Use nested list comprehension to extract each value from sub-lists in order.

```py
def flatten(lst):
return [x for y in lst for x in y]
```

```py
flatten([[1,2,3,4],[5,6,7,8]]) # [1, 2, 3, 4, 5, 6, 7, 8]
```

0 comments on commit 643aaf3

Please sign in to comment.