From 7ebb059255c9416288d0773302b6fc8e10e40145 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 20 Aug 2019 15:11:47 +0300 Subject: [PATCH] Add last snippet --- snippets/last.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/last.md diff --git a/snippets/last.md b/snippets/last.md new file mode 100644 index 000000000..84c216843 --- /dev/null +++ b/snippets/last.md @@ -0,0 +1,17 @@ +--- +title: last +tags: list,beginner +--- + +Returns the last element in a list. + +use `lst[-1]` to return the last element of the passed list. + +```py +def last(lst): + return lst[-1] +``` + +```py +last([1, 2, 3]) # 3 +```