I would like this search to check if all the numbers or words are in the line and add to the count if all are in the line. But if any one is not, go to the next line and do not add to count.
It looks like the and would be perfect for this although I have a varying user input so I don’t know how I would use it if I don’t know how many are entered ahead of time or if I can use it with split.
The program is only returning the last number entered now and seem to not take the others into consideration.
Thanks for the help.
Here is an example of what I am trying to do.
Enter the search file to look in feb_time.txt
Enter your search item 5 7 11
sample of what would be in look_in file
2 5 7 10 11 17 this would add to count
5 12 7 17 11 22 this would add to count
3 6 9 10 11 14 10 this would not add to count
2 of your search was found
This is my code
Expand|Select|Wrap|Line Numbers
- look_in = raw_input ("Enter the search file to look in ")
- search = raw_input ("Enter your search item ").split()
- txt = open(look_in)
- search2 = search
- line = txt.readline()
- while line:
- line = txt.readline()
- for item in search2:
- c = line.count(item)
- if c > 0: print "(",c,")", "Of your search was found"
- else: print item, "was not found"