How python finds multiple indexes of the same element in a list
This article mainly shows you "python how to find multiple indexes of the same element in a list", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "python how to find multiple indexes of the same element in a list" this article.
Definition: X = [1, 2, 3, 1, 4]
Task: find the index with element 1
Solution:
# if you directly use X.index (1), you can only get an index of 0, and we need all indexes .l = len (X) zip_list = zip (* (range (l), X)) id1 = [z [0] for iMager z in enumerate (zip_list) if z [1] = 1] # or a simpler id1 = [i for i X in enumerate (X) if x indexes 1] are all the contents of the article "how python finds multiple indexes of the same element in a list" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!