diff --git a/README.md b/README.md
index 9ff167463..f45b1d323 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,7 @@
* [`symmetric_difference`](#symmetric_difference)
* [`symmetric_difference_by`](#symmetric_difference_by)
* [`tail`](#tail)
+* [`transpose`](#transpose)
* [`union`](#union)
* [`union_by`](#union_by)
* [`unique_elements`](#unique_elements)
@@ -1053,6 +1054,28 @@ tail([1]); # [1]
[⬆ Back to top](#contents)
+### transpose
+
+Returns the transpose of a two-dimensional list.
+
+Use `*lst` to get the passed list as tuples.
+Use `zip()` in combination with `list()` to create the transpose of the given two-dimensional list.
+
+```py
+def transpose(lst):
+ return list(zip(*lst))
+```
+
+
+Examples
+
+```py
+transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) # [(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)]
+```
+
+
+
[⬆ Back to top](#contents)
+
### union
Returns every element that exists in any of the two lists once.
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json
index 03697fcdc..cf3716450 100644
--- a/snippet_data/snippetList.json
+++ b/snippet_data/snippetList.json
@@ -1086,6 +1086,21 @@
"hash": "f06acf219bcdfbacb9e86b01f91c7d68f6f8fa8a5a043c37cf33de4969c62eae"
}
},
+ {
+ "id": "transpose",
+ "type": "snippetListing",
+ "title": "transpose",
+ "attributes": {
+ "text": "Returns the transpose of a two-dimensional list.\n\nUse `*lst` to get the passed list as tuples.\nUse `zip()` in combination with `list()` to create the transpose of the given two-dimensional list.\n\n",
+ "tags": [
+ "list",
+ "intermediate"
+ ]
+ },
+ "meta": {
+ "hash": "e5768f5c6d605587cf01697dd8e06c5dc7c91e60818871691730600c6fba4ec6"
+ }
+ },
{
"id": "union",
"type": "snippetListing",
diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json
index 152ca9f64..67679e191 100644
--- a/snippet_data/snippets.json
+++ b/snippet_data/snippets.json
@@ -1436,6 +1436,26 @@
"hash": "f06acf219bcdfbacb9e86b01f91c7d68f6f8fa8a5a043c37cf33de4969c62eae"
}
},
+ {
+ "id": "transpose",
+ "title": "transpose",
+ "type": "snippet",
+ "attributes": {
+ "fileName": "transpose.md",
+ "text": "Returns the transpose of a two-dimensional list.\n\nUse `*lst` to get the passed list as tuples.\nUse `zip()` in combination with `list()` to create the transpose of the given two-dimensional list.\n\n",
+ "codeBlocks": {
+ "code": "def transpose(lst):\n return list(zip(*lst))",
+ "example": "transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) # [(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)]"
+ },
+ "tags": [
+ "list",
+ "intermediate"
+ ]
+ },
+ "meta": {
+ "hash": "e5768f5c6d605587cf01697dd8e06c5dc7c91e60818871691730600c6fba4ec6"
+ }
+ },
{
"id": "union",
"title": "union",