+ 7
List index return not valid
When requesting index values from a list with identical items, the index value returned is not from the iteration, but from the first occurrence of list item. Is there a way to ascertain the index value of the repeated item? Code sample attached for clarification https://code.sololearn.com/cl13DK0N8pUi/?ref=app
6 Respostas
+ 1
I don't think there is a way around it, maybe if you do it manually
+ 1
Hi ✳AsterisK✳
Jay Matthews has embedded a code in a reply to my sample code which shows a work around.
Thanks for taking the time to look into it. 👍
+ 1
I know this is a late reply but...
List index method can take three params.....one of which is the starting index.
myint = 4
mylist = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
print(mylist.index(myint))
print(mylist.index(myint, mylist.index(myint)+1)) <- return 8, index of second '4'.
For more info:-https://docs.python.org/3/tutorial/datastructures.html
+ 1
rodwynnejones Thanks. I will play with this also
0
Thanks to Jay Matthews for his solution
0
Thanks Coder Kitten
Another great idea for me to play with.