You can use collections.Counter
for this, which will provide the lowest count found in either list for each element when you take the intersection.
from collections import Counter
c = list((Counter(a) & Counter(b)).elements())
Outputs:
[1, 1, 2, 3, 4]
More Related Contents:
- What is wrong with my python code? [duplicate]
- how to count average sentence length (in words) from a text file contains 100 sentences using python [closed]
- What needs to be added
- How to install PIL with pip on Mac OS?
- ImportError: numpy.core.multiarray failed to import
- Launch a completely independent process
- ReactorNotRestartable error in while loop with scrapy
- How to get PID by process name?
- Running powershell script within python script, how to make python print the powershell output while it is running
- Is it good practice to use `import __main__`?
- Python3 correct way to import relative or absolute?
- Use Multiple Character Delimiter in Python Pandas read_csv
- Cancellable threading.Timer in Python
- Python OrderedDict not keeping element order [duplicate]
- pandas: replace string with another string
- Why does ENcoding a string result in a DEcoding error (UnicodeDecodeError)?
- Pyodbc – “Data source name not found, and no default driver specified”
- how to merge two data frames based on particular column in pandas python?
- Python – Homework – Converting Any Base to Any Base
- How to solve import error for pandas?
- sum each value in a list of tuples
- Why does dict(k=4, z=2).update(dict(l=1)) return None in Python? [duplicate]
- How do I make matplotlib open a box for user comments?
- python_2_unicode_compatible error
- Get data from Twitter using Tweepy and store in csv file
- Run process with realtime output to a Tkinter GUI
- How to display charts in Spyder
- What does the slice() function do in Python?
- Any way to get one process to have a write lock and others to just read on parallel?
- Google Search Web Scraping with Python