Skip to content
Advertisement

Finding an index in a list

I have an html file which I open in notepad and read in python as list

JavaScript

the html is done like this:

JavaScript

I’m making a search on word “data” and from there I manipulate the string in order to get the data. Since I need to iterate this research and I don’t want to start everytime from the first “data”/”time”-row, is there a command to get the “index” of the row?

This is the main code:

JavaScript

this instead is the def:

JavaScript

I’ve located the error. Basically it is how I’m passing the information to lst. I mean: when iterazione=index=0 in the first cycle, lst starts from index 0 and this is ok when iterazione=index+1 (in the next cycle) this time lst will start from index 1 and the word “data” will be found at index 3. Then again in the next cycle iterazione=4 but this time lst will start from index 4 and this means that “data” will be found at index 0 so in the next loop the counter is wrong.

Advertisement

Answer

Use the enumerate method to get an additional index attribute while looping.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement