From 99374f1c2e50007826dfe22abe8ec714b88f99af Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Sun, 22 Sep 2019 12:23:27 +0000 Subject: [PATCH] Travis build: 98 --- README.md | 9 +++------ snippet_data/snippetList.json | 2 +- snippet_data/snippets.json | 6 +++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f4ab8e893..4af29ee3b 100644 --- a/README.md +++ b/README.md @@ -513,10 +513,7 @@ Use list comprehension to map each element to the appropriate `key`. ```py def group_by(lst, fn): - groups = {} - for key in list(map(fn,lst)): - groups[key] = [item for item in lst if fn(item) == key] - return groups + return {key : [el for el in lst if fn(el) == key] for key in map(fn,lst)} ```
@@ -524,8 +521,8 @@ def group_by(lst, fn): ```py import math -group_by([6.1, 4.2, 6.3], math.floor); # {4: [4.2], 6: [6.1, 6.3]} -group_by(['one', 'two', 'three'], len); # {3: ['one', 'two'], 5: ['three']} +group_by([6.1, 4.2, 6.3], math.floor) # {4: [4.2], 6: [6.1, 6.3]} +group_by(['one', 'two', 'three'], len) # {3: ['one', 'two'], 5: ['three']} ```
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index b2d0788e8..0649ed1e4 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -445,7 +445,7 @@ ] }, "meta": { - "hash": "8e552ea1be04303164bd9c480ebd7392bcc79ef620ce18ee6436dc1dc41c1e42" + "hash": "b3d1a5b7cd2f3b25f9d89efeba7f4eb7f9e4e6d81e108d57f94770c8f979428e" } }, { diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 066e4df0c..2e4a9cd14 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -580,8 +580,8 @@ "fileName": "group_by.md", "text": "Groups the elements of a list based on the given function.\n\nUse `list()` in combination with `map()` and `fn` to map the values of the list to the keys of an object.\nUse list comprehension to map each element to the appropriate `key`.\n\n", "codeBlocks": { - "code": "def group_by(lst, fn):\n groups = {}\n for key in list(map(fn,lst)):\n groups[key] = [item for item in lst if fn(item) == key]\n return groups", - "example": "import math\ngroup_by([6.1, 4.2, 6.3], math.floor); # {4: [4.2], 6: [6.1, 6.3]}\ngroup_by(['one', 'two', 'three'], len); # {3: ['one', 'two'], 5: ['three']}" + "code": "def group_by(lst, fn):\n return {key : [el for el in lst if fn(el) == key] for key in map(fn,lst)}", + "example": "import math\ngroup_by([6.1, 4.2, 6.3], math.floor) # {4: [4.2], 6: [6.1, 6.3]}\ngroup_by(['one', 'two', 'three'], len) # {3: ['one', 'two'], 5: ['three']}" }, "tags": [ "list", @@ -590,7 +590,7 @@ ] }, "meta": { - "hash": "8e552ea1be04303164bd9c480ebd7392bcc79ef620ce18ee6436dc1dc41c1e42" + "hash": "b3d1a5b7cd2f3b25f9d89efeba7f4eb7f9e4e6d81e108d57f94770c8f979428e" } }, {