You don’t need to define intersection. It’s already a first-class part of set.
>>> b1 = [1,2,3,4,5,9,11,15]
>>> b2 = [4,5,6,7,8]
>>> set(b1).intersection(b2)
set([4, 5])
More Related Contents:
- Removing duplicates in lists
- Python -Intersection of multiple lists?
- Deleting certain elements in a list [closed]
- Iterating over every two elements in a list [duplicate]
- What are the advantages of NumPy over regular Python lists?
- Remove all occurrences of a value from a list?
- How to check if all elements of a list match a condition?
- Check for presence of a sliced list in Python
- List of lists into numpy array
- Replace values in list using Python [duplicate]
- Pandas DataFrame to List of Dictionaries
- Add SUM of values of two LISTS into new LIST
- Splitting list based on missing numbers in a sequence
- Using an index to get an item
- Print LIST of unicode chars without escape characters
- Combining two lists and removing duplicates, without removing duplicates in original list
- Some built-in to pad a list in python
- Sort a list of lists with a custom compare function
- Python – sum values in dictionary
- Get unique values in List of Lists
- How to apply __str__ function when printing a list of objects in Python [duplicate]
- Filtering a list based on a list of booleans
- Convert list into a pandas dataframe
- Why does list ask about __len__?
- How to assign each element of a list to a separate variable? [duplicate]
- How to create a fix size list in python?
- python – get list of tuples first index?
- Find a value in a list [duplicate]
- Creating a list in Python- something sneaky going on?
- Rearranging list based on order of another list