Hi All,

I am writing a little program that i should be able to get working i think!

basically i have this file full of content and i want to search it for a list of words. And add to a score variable each time i find a word

scorelist = [ "<tr>" , "</tr>" ]

for i in scorelist:
   for line in f:
      if i in line:
         print i 
         score = score + 1

i have <tr> and </tr> in the file five times each yet score is only ever five.
It never moves up the list to look for "</tr>"

What is it that im doing wrong??
sorry but im new to python!

Thanks.. from a stuck irishman!

Hello again,

i got the answer to this in the end.

basically when i was after reading the file with the first element of the list, the pointer reading the file was at the end of the file. So i have to go back to the start of the file when i have finished reading each term.

Thanks anyway, am sure ill need you all again!!

commented: Thanks for the solution and attempting on your own. +7

Reverse the two for() statements so you only read the file once (and don't use i, l, or o as variable names. They look like numbers).

for line in f:
   for j in scorelist
      if j in line:
         print j
         score = score + 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.