>>> L1 = [2,3,4]
>>> L2 = [1,2]
>>> [i for i in L1 if i in L2]
[2]
>>> S1 = set(L1)
>>> S2 = set(L2)
>>> S1.intersection(S2)
set([2])
Both empty lists and empty sets are False, so you can use the value directly as a truth value.
More Related Contents:
- a pythonic way of doubling consecutive binary bits [closed]
- Filtering Pandas DataFrames on dates
- Showing the stack trace from a running Python application
- Unnest (explode) a Pandas Series
- Virtualenv Command Not Found
- plot with custom text for x axis points
- Pandas Pivot tables row subtotals
- Pandas: How do I assign values based on multiple conditions for existing columns?
- Is it feasible to compile Python to machine code?
- Escape special characters in a Python string
- Upload files in Google App Engine
- Calculate time difference between Pandas Dataframe indices
- How to read HDF5 files in Python
- Python Paramiko – Run command
- Changing variable names with Python for loops [duplicate]
- Python MYSQL update statement
- Python Pandas Conditional Sum with Groupby
- Using conditional to generate new column in pandas dataframe
- Certifacte verify failed: certificate has expired (_ssl.c:1108)
- Change default Python version from 2.4 to 2.6
- Splitting out the output of ps using Python
- How to split by comma and strip white spaces in Python?
- How can I dynamically create class methods for a class in python [duplicate]
- Find starting and ending indices of sublist in list
- Converting List Comprehensions to For Loops in Python
- Python making combined bar and line plot with secondary y-axis
- How to resample a dataframe with different functions applied to each column?
- Writing to a new file if it doesn’t exist, and appending to a file if it does
- Understanding scipy deconvolve
- how to add Row id in pySpark dataframes [duplicate]