From 643aaf3a3154b3406d9694abe2f15c3e3566e73e Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 19 Sep 2019 07:46:10 -0500 Subject: [PATCH 1/2] Added Flatten() --- snippets/flatten.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/flatten.md diff --git a/snippets/flatten.md b/snippets/flatten.md new file mode 100644 index 000000000..0687b3a4e --- /dev/null +++ b/snippets/flatten.md @@ -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] +``` From 8f80a2923264f5ff9f1a2e5b8b7f7fbaf9083c5e Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 19 Sep 2019 20:43:36 +0300 Subject: [PATCH 2/2] Update flatten.md --- snippets/flatten.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/flatten.md b/snippets/flatten.md index 0687b3a4e..f2306241b 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -3,7 +3,7 @@ title: flatten tags: list,intermediate --- -Flattens a list of lists. +Flattens a list of lists once. Use nested list comprehension to extract each value from sub-lists in order.