February 6th, 2010, 12:37 AM
Join Date: Feb 2010
Time spent in forums: 13 m 23 sec
Reputation Power: 0
Help to make search work
I am new to programing so forgive me if my code is amicher.
I am trying to have the search return several numbers or words in a single sentences. I don't know if I am using the wrong format I am trying to use the split method because I thought I could return several parts of a sentence with it. For example if it had 1 2 3 4 5 I thought I could search and return 1 3 5 or if it had “to set the function” I could return “set function” from that line, but I can’t get it working properly.
I have tried several different approaches with split. I have tried to split it at the raw_input() line, at the if statement, putting it in a loop and declaring it separately.
I have looked up, in the python library to make sure I am entering it properly. It will ether run trough and not work like I expect or it will come up with an error.
I think I am using the right method in the wrong way. If you could tell me if I am trying the correct method or give me a push in the right direction that would be grate thanks.
This is the code I am using less the split() method becaues I cant get it to work.
look_in = raw_input ("Enter the search file to look in ")
search = raw_input ("Enter your search item ")
file = open(look_in, "r").read().count(search)
if file: print search, ",", file,"Of your search was found"
else: print "Your search was not found"
This is what I would like it to do.
Enter your search item 50 150
#example of text in document
April1, 50 100 150 100 200
April2, 100 50 200 50 250
April3, 100 50 150 200 100
2 of your search was found
So it would look for the 50 and 150 in each line then print how many times they are in the same line together in the same order.