diff --git a/README.md b/README.md
index 97ae4852c..30ddf1102 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,7 @@
* [`every`](#every)
* [`every_nth`](#every_nth)
* [`filter_non_unique`](#filter_non_unique)
+* [`flatten`](#flatten)
* [`group_by`](#group_by)
* [`has_duplicates`](#has_duplicates)
* [`head`](#head)
@@ -482,6 +483,27 @@ filter_non_unique([1, 2, 2, 3, 4, 4, 5]) # [1, 3, 5]
[⬆ Back to top](#contents)
+### flatten
+
+Flattens a list of lists once.
+
+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]
+```
+
+
+Examples
+
+```py
+flatten([[1,2,3,4],[5,6,7,8]]) # [1, 2, 3, 4, 5, 6, 7, 8]
+```
+
+
+
[⬆ Back to top](#contents)
+
### group_by
Groups the elements of a list based on the given function.
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json
index 8f250e9c0..31eb45c42 100644
--- a/snippet_data/snippetList.json
+++ b/snippet_data/snippetList.json
@@ -402,6 +402,21 @@
"hash": "05679ae115d276830ec769a04b0800d92eabc6a09678fc1a9cf6013c813cc650"
}
},
+ {
+ "id": "flatten",
+ "type": "snippetListing",
+ "title": "flatten",
+ "attributes": {
+ "text": "Flattens a list of lists once.\n\nUse nested list comprehension to extract each value from sub-lists in order.\n\n",
+ "tags": [
+ "list",
+ "intermediate"
+ ]
+ },
+ "meta": {
+ "hash": "49b4f976c9050c9cb6fe038653fc3dbc88135086255c06c4f46b746b21bfb544"
+ }
+ },
{
"id": "gcd",
"type": "snippetListing",
diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json
index a64d4144e..2f6888050 100644
--- a/snippet_data/snippets.json
+++ b/snippet_data/snippets.json
@@ -532,6 +532,26 @@
"hash": "05679ae115d276830ec769a04b0800d92eabc6a09678fc1a9cf6013c813cc650"
}
},
+ {
+ "id": "flatten",
+ "title": "flatten",
+ "type": "snippet",
+ "attributes": {
+ "fileName": "flatten.md",
+ "text": "Flattens a list of lists once.\n\nUse nested list comprehension to extract each value from sub-lists in order.\n\n",
+ "codeBlocks": {
+ "code": "def flatten(lst):\n return [x for y in lst for x in y]",
+ "example": "flatten([[1,2,3,4],[5,6,7,8]]) # [1, 2, 3, 4, 5, 6, 7, 8]"
+ },
+ "tags": [
+ "list",
+ "intermediate"
+ ]
+ },
+ "meta": {
+ "hash": "49b4f976c9050c9cb6fe038653fc3dbc88135086255c06c4f46b746b21bfb544"
+ }
+ },
{
"id": "gcd",
"title": "gcd",