From b65a89ed00b80fe4681d24c33d7deec6f12a7f1c Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Tue, 8 Oct 2019 06:41:17 +0000 Subject: [PATCH] Travis build: 145 --- README.md | 22 ++++++++++++++++++++++ snippet_data/snippetList.json | 15 +++++++++++++++ snippet_data/snippets.json | 20 ++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/README.md b/README.md index 77a7ffd6a..9ff167463 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ * [`every`](#every) * [`every_nth`](#every_nth) * [`filter_non_unique`](#filter_non_unique) +* [`filter_unique`](#filter_unique) * [`flatten`](#flatten) * [`group_by`](#group_by) * [`has_duplicates`](#has_duplicates) @@ -478,6 +479,27 @@ filter_non_unique([1, 2, 2, 3, 4, 4, 5]) # [1, 3, 5]
[⬆ Back to top](#contents) +### filter_unique + +Filters out the unique values in a list. + +Use list comprehension and `list.count()` to create a list containing only the non-unique values. + +```py +def filter_unique(lst): + return [x for x in set(item for item in lst if lst.count(item) > 1)] +``` + +
+Examples + +```py +filter_unique([1, 2, 2, 3, 4, 4, 5]) # [2, 4] +``` +
+ +
[⬆ Back to top](#contents) + ### flatten Flattens a list of lists once. diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index 9296bf342..03697fcdc 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -402,6 +402,21 @@ "hash": "05679ae115d276830ec769a04b0800d92eabc6a09678fc1a9cf6013c813cc650" } }, + { + "id": "filter_unique", + "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", + "tags": [ + "list", + "beginner" + ] + }, + "meta": { + "hash": "174c62134c81e139aa9d0b31f46c684b5edd4c52e721136d586d435058e19288" + } + }, { "id": "flatten", "type": "snippetListing", diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 2d17805d5..152ca9f64 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -532,6 +532,26 @@ "hash": "05679ae115d276830ec769a04b0800d92eabc6a09678fc1a9cf6013c813cc650" } }, + { + "id": "filter_unique", + "title": "filter_unique", + "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", + "codeBlocks": { + "code": "def filter_unique(lst):\n return [x for x in set(item for item in lst if lst.count(item) > 1)]", + "example": "filter_unique([1, 2, 2, 3, 4, 4, 5]) # [2, 4]" + }, + "tags": [ + "list", + "beginner" + ] + }, + "meta": { + "hash": "174c62134c81e139aa9d0b31f46c684b5edd4c52e721136d586d435058e19288" + } + }, { "id": "flatten", "title": "flatten",