[New-bugs-announce] [issue47094] index doesn't change while looping through same elements in a list

Tk44 report at bugs.python.org
Tue Mar 22 11:09:35 EDT 2022


New submission from Tk44 <tugberk at gmail.com>:

Let us define a list where there are some duplicate elements. If we loop through that list as "for i in my_list" and print the index by my_list.index(i); the index doesn't change.

e.g.

my_list = [1,1,1,1,3]
for elm in my_list:
   print(my_list.index(elm))

==output==
0
0
0
0
4

This occurs where elements are of type string as well. Of course this can be overcome by using enumerate(); however I think this is a wrong behavior.

----------
messages: 415785
nosy: Tugberk
priority: normal
severity: normal
status: open
title: index doesn't change while looping through same elements in a list
type: behavior
versions: Python 3.9

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


More information about the New-bugs-announce mailing list