From c0781a97c62889d5396dbbb59e53dd396d8053e0 Mon Sep 17 00:00:00 2001 From: Lazar Gugleta Date: Fri, 11 Oct 2019 23:26:36 +0200 Subject: [PATCH 1/5] add snippet try else --- snippets/try_else.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 snippets/try_else.md diff --git a/snippets/try_else.md b/snippets/try_else.md new file mode 100644 index 000000000..444fb556c --- /dev/null +++ b/snippets/try_else.md @@ -0,0 +1,18 @@ +--- +title: Try else +tags: utility,intermediate +--- + +Rises an `exception` if it is caught in the `try` block. + +You can have an else clause as part of a `try/except` block, which is executed if no `exception` is thrown. + +```py +try: + 5*6 +except TypeError: + print("An exception was raised") +else: + print("No exceptions were raised.") +``` + From 38529f33c8736c5074dd42aac1802547bb36120f Mon Sep 17 00:00:00 2001 From: Lazar Gugleta Date: Fri, 11 Oct 2019 23:40:49 +0200 Subject: [PATCH 2/5] add most frequent snippet --- snippets/most_frequent.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 snippets/most_frequent.md diff --git a/snippets/most_frequent.md b/snippets/most_frequent.md new file mode 100644 index 000000000..926d0dddd --- /dev/null +++ b/snippets/most_frequent.md @@ -0,0 +1,19 @@ +--- +title: most_frequent +tags: array,beginner +--- + +Method return the most frequent element that appears in a `list`. + +Upon calling the function, in return you a `value`, which most frequently appears in the `list`. + +```py +def most_frequent(list): + return max(set(list), key = list.count) +``` + +```py +numbers = [1,2,1,2,3,2,1,4,2] +most_frequent(numbers) #2 +``` + From bd95708f8d82521017bf58aa4b2488fcb3951ece Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 12 Oct 2019 12:54:06 +0300 Subject: [PATCH 3/5] Delete try_else.md --- snippets/try_else.md | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 snippets/try_else.md diff --git a/snippets/try_else.md b/snippets/try_else.md deleted file mode 100644 index 444fb556c..000000000 --- a/snippets/try_else.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: Try else -tags: utility,intermediate ---- - -Rises an `exception` if it is caught in the `try` block. - -You can have an else clause as part of a `try/except` block, which is executed if no `exception` is thrown. - -```py -try: - 5*6 -except TypeError: - print("An exception was raised") -else: - print("No exceptions were raised.") -``` - From 907bb897054b0ee6538ef7004651d2f9d63f6810 Mon Sep 17 00:00:00 2001 From: Lazar Gugleta Date: Sat, 12 Oct 2019 12:07:20 +0200 Subject: [PATCH 4/5] fix snippet most frequent --- snippets/most_frequent.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/snippets/most_frequent.md b/snippets/most_frequent.md index 926d0dddd..69b677626 100644 --- a/snippets/most_frequent.md +++ b/snippets/most_frequent.md @@ -1,19 +1,18 @@ --- title: most_frequent -tags: array,beginner +tags: list,beginner --- -Method return the most frequent element that appears in a `list`. +Returns the most frequent element in a `list`. -Upon calling the function, in return you a `value`, which most frequently appears in the `list`. +Use `set(list)` to get the unique values in the `list` in combination `max()` to find the element that has the most appearances. ```py def most_frequent(list): - return max(set(list), key = list.count) + return max(set(list), key = list.count) ``` ```py numbers = [1,2,1,2,3,2,1,4,2] most_frequent(numbers) #2 -``` - +``` \ No newline at end of file From 82b8ec08f65beef09b4c3399c7f236400e915e96 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 12 Oct 2019 13:14:17 +0300 Subject: [PATCH 5/5] Update most_frequent.md --- snippets/most_frequent.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/snippets/most_frequent.md b/snippets/most_frequent.md index 69b677626..426335470 100644 --- a/snippets/most_frequent.md +++ b/snippets/most_frequent.md @@ -3,9 +3,9 @@ title: most_frequent tags: list,beginner --- -Returns the most frequent element in a `list`. +Returns the most frequent element in a list. -Use `set(list)` to get the unique values in the `list` in combination `max()` to find the element that has the most appearances. +Use `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances. ```py def most_frequent(list): @@ -13,6 +13,5 @@ def most_frequent(list): ``` ```py -numbers = [1,2,1,2,3,2,1,4,2] -most_frequent(numbers) #2 -``` \ No newline at end of file +most_frequent([1,2,1,2,3,2,1,4,2]) #2 +```