diff --git a/README.md b/README.md
index 93d7deb2d..2d92d46ff 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,7 @@
* [`is_odd`](#is_odd)
* [`lcm`](#lcm-)
* [`max_by`](#max_by)
+* [`median`](#median)
* [`min_by`](#min_by)
* [`rads_to_degrees`](#rads_to_degrees)
* [`sum_by`](#sum_by)
@@ -1456,6 +1457,33 @@ max_by([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], lambda v : v['n']) # 8
[⬆ Back to top](#contents)
+### median
+
+Finds the median of a list of numbers.
+
+Sort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even.
+
+```py
+def median(list):
+ list.sort()
+ list_length = len(list)
+ if list_length%2==0:
+ return (list[int(list_length/2)-1] + list[int(list_length/2)])/2
+ else:
+ return list[int(list_length/2)]
+```
+
+
+Examples
+
+```py
+median([1,2,3]) # 2
+median([1,2,3,4]) # 2.5
+```
+
+
+
[⬆ Back to top](#contents)
+
### min_by
Returns the minimum value of a list, after mapping each element to a value using the provided function.
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json
index 0969948a0..b9a08c9de 100644
--- a/snippet_data/snippetList.json
+++ b/snippet_data/snippetList.json
@@ -774,6 +774,21 @@
"hash": "a87775ce6bd1590c7c7b31b7dfce03b00120e4e8183c65cec8fdd3841fa369d7"
}
},
+ {
+ "id": "median",
+ "type": "snippetListing",
+ "title": "median",
+ "attributes": {
+ "text": "Finds the median of a list of numbers.\n\nSort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even.\n\n",
+ "tags": [
+ "math",
+ "beginner"
+ ]
+ },
+ "meta": {
+ "hash": "a2f09e1423bde7161422814e3ecdb2ce77dac812df719ea60c37f55c06a06705"
+ }
+ },
{
"id": "min_by",
"type": "snippetListing",
diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json
index a78443343..cec010a19 100644
--- a/snippet_data/snippets.json
+++ b/snippet_data/snippets.json
@@ -1024,6 +1024,26 @@
"hash": "a87775ce6bd1590c7c7b31b7dfce03b00120e4e8183c65cec8fdd3841fa369d7"
}
},
+ {
+ "id": "median",
+ "title": "median",
+ "type": "snippet",
+ "attributes": {
+ "fileName": "median.md",
+ "text": "Finds the median of a list of numbers.\n\nSort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even.\n\n",
+ "codeBlocks": {
+ "code": "def median(list):\n list.sort()\n list_length = len(list)\n if list_length%2==0:\n return (list[int(list_length/2)-1] + list[int(list_length/2)])/2\n else:\n return list[int(list_length/2)]",
+ "example": "median([1,2,3]) # 2\nmedian([1,2,3,4]) # 2.5"
+ },
+ "tags": [
+ "math",
+ "beginner"
+ ]
+ },
+ "meta": {
+ "hash": "a2f09e1423bde7161422814e3ecdb2ce77dac812df719ea60c37f55c06a06705"
+ }
+ },
{
"id": "min_by",
"title": "min_by",