Extract multiple list duplicates in Python

There are some similar articles, but I'll leave them because I find the collections.Counter method to be easy and convenient.

from collections import Counter

hoge = ['a', 'b', 'c', 'd', 'e']
fuga = ['c', 'd', 'e', 'f', 'g']

Counter(hoge + fuga)
# => Counter({'a': 1, 'b': 1, 'c': 2, 'd': 2, 'e': 2, 'f': 1, 'g': 1})

#Two or more elements
[k for k, v in Counter(hoge + fuga).items() if v > 1]
# => ['c', 'd', 'e']

Recommended Posts

Extract multiple list duplicates in Python
Delete multiple elements in python list
Sorted list in Python
Filter List in Python
List find in Python
Multiple regression expressions in Python
Specify multiple list indexes (Python)
Avoid multiple loops in Python
Getting list elements in Python
Prohibit multiple launches in python
[Python] Show multiple windows in Tkinter
Difference between list () and [] in Python
[python] Manage functions in a list
Output 2017 Premium Friday list in Python
Extract text from images in Python
Statistical test (multiple test) in Python: scikit_posthocs
[Python] list
Extract strings from files in Python
How to delete multiple specified positions (indexes) in a Python list
Handle multiple python versions in one jupyter
When specifying multiple keys in python sort
Display a list of alphabets in Python 3
OR the List in Python (zip function)
Send email to multiple recipients in Python (Python 3)
Difference between append and + = in Python list
How to extract polygon area in Python
Process multiple lists with for in Python
Download images from URL list in Python
Summary of built-in methods in Python list
Get the EDINET code list in Python
[Python] Understand list slicing operations in seconds
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Python basics: list
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Extract every n elements from an array (list) in Python and Ruby
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
Python> Comprehension / Comprehension> List comprehension
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python