The best way to do this would be to make b
a set
since you are only checking for membership inside it.
>>> a = [1, 2, 3, 4, 5]
>>> b = set([9, 7, 6, 5, 1, 0])
>>> [i for i, item in enumerate(a) if item in b]
[0, 4]
More Related Contents:
- How to find all occurrences of an element in a list
- TypeError: list indices must be integers or slices, not list
- convert string to list [duplicate]
- Unable to use convert strings into integers for a for loop
- Strange result when removing item from a list while iterating over it
- How to merge lists into a list of tuples?
- Pythonic way to print list items
- Pythonic way to check if a list is sorted or not
- Detecting consecutive integers in a list [duplicate]
- Non-alphanumeric list order from os.listdir()
- How do I check if there are duplicates in a flat list?
- Python – use list as function parameters
- Memory errors and list limits?
- Sum of list of lists; returns sum list
- List of tuples to dictionary [duplicate]
- [] and {} vs list() and dict(), which is better?
- How to access List elements
- Group by multiple keys and summarize/average values of a list of dictionaries
- Python: Removing spaces from list objects [duplicate]
- Initializing 2D array in Python
- How do I merge multiple lists into one list? [duplicate]
- How can I format a list to print each element on a separate line in python? [duplicate]
- Group list by values [duplicate]
- Python: filtering lists by indices
- What are dict_keys, dict_items and dict_values?
- Ordered intersection of two lists in Python
- What to consider before subclassing list?
- What is the cost/ complexity of insert in list at some location?
- Nested lambda statements when sorting lists
- Check list monotonicity