Find the second index of an element in a list in Python
hello We have a list like this:
list1 = ["a", "b", "c", "b"]
میخوام بدونم چطوری میشه ایندکس دومِ "b" رو پیدا کرد؟ It means the index corresponding to the second "b" in the list.
hello We have a list like this:
list1 = ["a", "b", "c", "b"]
میخوام بدونم چطوری میشه ایندکس دومِ "b" رو پیدا کرد؟ It means the index corresponding to the second "b" in the list.
list1 = ["a", "b", "c", "b"]
index_second_b = [i for i, x in enumerate(list1) if x == "b"][1]
print(index_second_b) # Output: 3
list1.1
It must be 1 because numbers in Python start from 0
He wants the second b, not the first
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.