[issue42026] index function return first index for same element if repetitive in a list

Raymond Hettinger report at bugs.python.org
Tue Oct 13 06:00:22 EDT 2020


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

The index() method is working as expected.  This isn't a bug.

The easiest way to accomplish your goal is to use enumerate() with a list comprehension:

    >>> po = [11,22,33,44,11,55,66,11,88]
    >>> [i for i, value in enumerate(po) if value == 11]
    [0, 4, 7]

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42026>
_______________________________________


More information about the Python-bugs-list mailing list