diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index 0cf2ef368..3f14fbba7 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -482,14 +482,14 @@ "type": "snippetListing", "title": "filter_non_unique", "attributes": { - "text": "Filters out the non-unique values in a list.\n\nUse list comprehension and `list.count()` to create a list containing only the unique values.\n\n", + "text": "Filters out the non-unique values in a list.\n\nUse a `Counter` to get the count of each value in the list.\nUse list comprehension to create a list containing only the unique values.\n\n", "tags": [ "list", "beginner" ] }, "meta": { - "hash": "05679ae115d276830ec769a04b0800d92eabc6a09678fc1a9cf6013c813cc650" + "hash": "cc048906b1a368428244af8202aeb3a60b1b7b7bf52ad744e92d3e21f6be95f2" } }, { @@ -497,14 +497,14 @@ "type": "snippetListing", "title": "filter_unique", "attributes": { - "text": "Filters out the unique values in a list.\n\nUse list comprehension and `list.count()` to create a list containing only the non-unique values.\n\n", + "text": "Filters out the unique values in a list.\n\nUse a `Counter` to get the count of each value in the list.\nUse list comprehension to create a list containing only the non-unique values.\n\n", "tags": [ "list", "beginner" ] }, "meta": { - "hash": "174c62134c81e139aa9d0b31f46c684b5edd4c52e721136d586d435058e19288" + "hash": "f3e5cada914ae863ca9cf8fd8780b1634ea526d78f1f542c5c7577f6dd685cfc" } }, { diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 18fa81cc8..c6dda92de 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -762,9 +762,9 @@ "type": "snippet", "attributes": { "fileName": "filter_non_unique.md", - "text": "Filters out the non-unique values in a list.\n\nUse list comprehension and `list.count()` to create a list containing only the unique values.\n\n", + "text": "Filters out the non-unique values in a list.\n\nUse a `Counter` to get the count of each value in the list.\nUse list comprehension to create a list containing only the unique values.\n\n", "codeBlocks": { - "code": "def filter_non_unique(lst):\n return [item for item in lst if lst.count(item) == 1]", + "code": "from collections import Counter\n\ndef filter_non_unique(lst):\n return [item for item, count in counter = Counter(lst).items() if count == 1]", "example": "filter_non_unique([1, 2, 2, 3, 4, 4, 5]) # [1, 3, 5]" }, "tags": [ @@ -773,11 +773,11 @@ ] }, "meta": { - "hash": "05679ae115d276830ec769a04b0800d92eabc6a09678fc1a9cf6013c813cc650", + "hash": "cc048906b1a368428244af8202aeb3a60b1b7b7bf52ad744e92d3e21f6be95f2", "firstSeen": "1566296031", - "lastUpdated": "1566296031", - "updateCount": 2, - "authorCount": 2 + "lastUpdated": "1578227946", + "updateCount": 4, + "authorCount": 3 } }, { @@ -786,9 +786,9 @@ "type": "snippet", "attributes": { "fileName": "filter_unique.md", - "text": "Filters out the unique values in a list.\n\nUse list comprehension and `list.count()` to create a list containing only the non-unique values.\n\n", + "text": "Filters out the unique values in a list.\n\nUse a `Counter` to get the count of each value in the list.\nUse list comprehension to create a list containing only the non-unique values.\n\n", "codeBlocks": { - "code": "def filter_unique(lst):\n return [x for x in set(item for item in lst if lst.count(item) > 1)]", + "code": "from collections import Counter\n\ndef filter_unique(lst):\n return [item for item, count in Counter(lst).items() if count > 1]", "example": "filter_unique([1, 2, 2, 3, 4, 4, 5]) # [2, 4]" }, "tags": [ @@ -797,11 +797,11 @@ ] }, "meta": { - "hash": "174c62134c81e139aa9d0b31f46c684b5edd4c52e721136d586d435058e19288", + "hash": "f3e5cada914ae863ca9cf8fd8780b1634ea526d78f1f542c5c7577f6dd685cfc", "firstSeen": "1570035984", - "lastUpdated": "1570516752", - "updateCount": 4, - "authorCount": 3 + "lastUpdated": "1578227961", + "updateCount": 7, + "authorCount": 4 } }, {