diff --git a/snippets/drop.md b/snippets/drop.md new file mode 100644 index 000000000..c00bcbe24 --- /dev/null +++ b/snippets/drop.md @@ -0,0 +1,19 @@ +--- +title: drop +tags: list,beginner +--- + +Returns a list with `n` elements removed from the left. + +Use slice notation to remove the specified number of elements from the left. + +```py +def drop(a, n = 1): + return a[n:] +``` + +```py +drop([1, 2, 3]) # [2, 3] +drop([1, 2, 3], 2) # [3] +drop([1, 2, 3], 42) # [] +``` diff --git a/snippets/drop_right.md b/snippets/drop_right.md new file mode 100644 index 000000000..21eaa672c --- /dev/null +++ b/snippets/drop_right.md @@ -0,0 +1,19 @@ +--- +title: drop_right +tags: list,beginner +--- + +Returns a list with `n` elements removed from the right. + +Use slice notation to remove the specified number of elements from the right. + +```py +def drop_right(a, n = 1): + return a[:-n] +``` + +```py +drop_right([1, 2, 3]) # [1, 2] +drop_right([1, 2, 3], 2) # [1] +drop_right([1, 2, 3], 42) # [] +```