Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

With python; Getting index of wrong item of list

I’m trying to get the indeces of the items of my list but on one item it returns a wrong index. There are two numbers who are the same in the list, maybe it confuses it with the first one.

The list is: [0,1,0,0,0,0,0,0,0,0,6,1,0]

for i in neu:

   if (i > 0):

      zahl = neu.index(i) + 7
      print(zahl)

      browser.find_element_by_xpath("//*[@id='tabelle_merkliste']/tbody/tr['zahl']/td[10]/img")

      print("found")

"print(Zahl)" returns these sums:
8
17
8 (should be 18)
Maybe someone got an idea why this happens, thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use enumerate:

for i, value in enumerate(neu):
    if (value > 0):

      zahl = i + 7
      print(zahl)

      browser.find_element_by_xpath("//*[@id='tabelle_merkliste']/tbody/tr['zahl']/td[10]/img")

      print("found")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading