Use enumerate
here
>>> l = ['A','A','B','A','B','B','A'] >>> [i for i,d in enumerate(l) if d=='B'] [2, 4, 5]
Related Posts:
- Python – TypeError: ‘int’ object is not iterable
- Python – TypeError: ‘int’ object is not iterable
- What does the list() function do in Python?
- How to return dictionary keys as a list in Python?
- Python cant convert ‘list’ object to str error [closed]
- SyntaxError: unexpected EOF while parsing
- How can I reverse a list in Python?
- Difference between del, remove, and pop on lists
- How can I reverse a list in Python?
- How to use filter, map, and reduce in Python 3
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- What is the difference between Python’s list methods append and extend?
- How can I make a time delay in Python? [duplicate]
- Understanding slice notation
- Understanding slice notation
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to open a file using the open with statement
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- TypeError: list indices must be integers or slices, not str
- How to install pip with Python 3?
- What is the difference between rw+ and r+
- IndexError: list index out of range and python
- Import Error: No module named numpy
- Python: ‘ModuleNotFoundError’ when trying to import module from imported package
- Relative imports – ModuleNotFoundError: No module named x
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How to uninstall a package installed with pip install –user
- How do I get the number of elements in a list?
- Relative imports in Python 3
- Finding the index of an item in a list
- Finding the index of an item in a list
- Accessing the index in ‘for’ loops?
- How to make a flat list out of a list of lists
- Removing duplicates in lists
- Best way to convert string to bytes in Python 3?
- Best way to convert string to bytes in Python 3?
- TypeError: not all arguments converted during string formatting python
- List changes unexpectedly after assignment. Why is this and how can I prevent it?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- PermissionError: [Errno 13] Permission denied
- What is setup.py?
- How is Anaconda related to Python?
- FileNotFoundError: [WinError 2] The system cannot find the file specified:
- TypeError: ‘float’ object is not subscriptable
- Is there a short contains function for lists?
- Invalid character in identifier
- TypeError: ‘float’ object is not subscriptable
- Transpose/Unzip Function (inverse of zip)?
- appending list but error ‘NoneType’ object has no attribute ‘append’
- Using Python 3 in virtualenv
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- How to remove EOFError: EOF when reading a line?
- WinError 2 The system cannot find the file specified (Python)
- Check if something is (not) in a list in Python
- hashlib.md5() TypeError: Unicode-objects must be encoded before hashing
- TypeError: cannot unpack non-iterable NoneType object
- Is there a ‘foreach’ function in Python 3?
- Python: finding an element in a list [duplicate]
- Python inline if statement
- How to install python3 version of package via pip on Ubuntu?
- Updating a dictionary in python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Could not find a version that satisfies the requirement tensorflow
- Convert bytes to a string
- How to copy a dictionary and only edit the copy
- How to print like printf in Python3?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Could not find a version that satisfies the requirement tensorflow
- Local variable referenced before assignment?
- Finding the average of a list
- Writing a list to a file with Python
- AttributeError: ‘module’ object has no attribute ‘urlopen’
- How do I concatenate two lists in Python?
- if else in a list comprehension
- How can I randomly select an item from a list?
- Python Error: AttributeError: __enter__ [duplicate]
- Print a list in reverse order with range()?
- Can’t fix “zipimport.ZipImportError: can’t decompress data; zlib not available” when I type in “python3.6 get-pip.py”
- Get unique values from a list in python [duplicate]
- Fastest way to check if a value exists in a list
- TypeError: ‘float’ object not iterable
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- How can I count the occurrences of a list item?
- TypeError: ‘list’ object cannot be interpreted as an integer
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- ‘method’ object is not subscriptable. Don’t know what’s wrong
- Invalid character in identifier
- Importing class from another file [duplicate]
- filedialog, tkinter and opening files
- How do I concatenate two lists in Python?
- if else in a list comprehension
- Finding median of list in Python
- Python set to list
- Python List vs. Array – when to use?
- error UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte
- Error in Python script “Expected 2D array, got 1D array instead:”?
- How to find all occurrences of an element in a list