This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dennis Sweeney
Recipients Dennis Sweeney, Tugberk
Date 2022-03-22.18:27:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1647973650.41.0.935972206508.issue47094@roundup.psfhosted.org>
In-reply-to
Content
The help text says this:

    >>> help(list.index)
    Help on method_descriptor:
    
    index(self, value, start=0, stop=9223372036854775807, /)
        Return first index of value.
        
        Raises ValueError if the value is not present.

Emphasis on *first* index. Example:

>>> L = [0, 10, 20, 33, 0, 10]
>>> L.index(10)
1
>>> L[5]
10
>>> L.index(L[5]) # the same meaning as L.index(10)
1

In your code, when elm has the value 1, it's just the value 1; there's no extra information carried along about where that 1 came from. If elm == 1, then my_list.index(elm) means the same as my_list.index(1).

I'd suggest taking any further questions to either StackOverflow or https://discuss.python.org/c/users/

Thanks for the concern, but I'm closing this as "not a bug". Changing this behavior now would be backwards-incompatible and break lots of people's code.
History
Date User Action Args
2022-03-22 18:27:30Dennis Sweeneysetrecipients: + Dennis Sweeney, Tugberk
2022-03-22 18:27:30Dennis Sweeneysetmessageid: <1647973650.41.0.935972206508.issue47094@roundup.psfhosted.org>
2022-03-22 18:27:30Dennis Sweeneylinkissue47094 messages
2022-03-22 18:27:30Dennis Sweeneycreate