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

I can't iterate through my list, it just says "list indices must be integers or slices, not str"

I am trying to check through a list to see if any of the strings inside it contain the word "Temperature" and I’m trying to use a for loop to do this but it doesn’t seem to want to work.
It seems like it won’t iterate because the list is all strings but I’ve used a for loop to iterate through strings before so I’m not sure what I’m doing wrong.

I would appreciate any help.
Thank you

My Code

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

The Error Message

>Solution :

You are trying to retrieve the value by str as the error says.
Try this:

print(i)

As you’ll see, you’ll get str.

A solution for this problem is as follows

  1. Remove line = split_lines[i]
  2. Change line.contains("Temperature") to "Temperature" in i
  3. temperature_string = i
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