473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I get my search to return more then one word or number in a sentences

I am a beginner so forgive me if my code looks like a joke.

I can return a single character, but I don't know if I am using the wrong format I was trying the split method because I thought I could return several parts of a sentence for example if it had 1 2 3 4 5 6 7 I thought I could search and return
2 5 7 but it will only work if they are next to each other or an exact match I guess. I may have don it incorrectly. I couldn't make the split work.

This is the last somewhat working version I had.
Expand|Select|Wrap|Line Numbers
  1. look_in = raw_input ("Enter the search file to look in ")
  2. search = raw_input ("Enter your search item ")
  3. file = open(look_in, "r").read().count(search)
  4. if file:   print search, ",", file,"Of your search was found"
  5. else:   print "Your search was not found"
If anyone could help or point me in the right direction I would appreciate it.
Thanks for your time and help.
Feb 1 '10 #1
1 1369
bvdet
2,851 Expert Mod 2GB
Please use code tags when posting code.

You are on the right track with split. You need to loop on the list that results from the split. Here's an example: I have a file full of 5 letter words. I will skip the raw_input.
Expand|Select|Wrap|Line Numbers
  1. fn = "fiveLetterWords.txt"
  2. # Do not use "file" for a variable name.
  3. # The built-in function "file()" will be masked.
  4. fileStr = open(fn).read().lower()
  5. words = 'Clunk,unite,fatal,PLIES,abstemious'
  6. for word in words.lower().split(','):
  7.     i = fileStr.count(word)
  8.     print ("There %s %d occurrence%s of %s in file %s" % \
  9.            (["is", "are"][(i>1 or i==0) or 0],
  10.             i, ["", "s"][(i>1 or i==0) or 0], word, fn))
The output:
Expand|Select|Wrap|Line Numbers
  1. >>> There is 1 occurrence of clunk in file fiveLetterWords.txt
  2. There is 1 occurrence of unite in file fiveLetterWords.txt
  3. There is 1 occurrence of fatal in file fiveLetterWords.txt
  4. There is 1 occurrence of plies in file fiveLetterWords.txt
  5. There are 0 occurrences of abstemious in file fiveLetterWords.txt
  6. >>> 
Please ask if you have any questions about the code I posted.
Feb 2 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alexandre Plennevaux | last post by:
hello mates, i want to set up a searchable database out of a huge word document containing reglementary articles (75 pages). The way i want the system to work is as such: a search form...
0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
1
by: Jack-of-all-traits | last post by:
This is a big problem and I really need help, no one seems to know how to solve this problem. I want to take the data from a record in a particular a field that contains the names of generic...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
64
by: Manfred Kooistra | last post by:
I am building a website with identical content in four different languages. On a first visit, the search engine determines the language of the content by the IP address of the visitor. What the...
3
by: wsnyder3 | last post by:
I am trying to create a search where the user can type in a word and if there are any matching word(s) on any table that it will display the tables matches. I am not real familiar with Access I am...
3
by: Russell | last post by:
Hey, ok i have numerous tables to search through for a 'site search'. some of the searchble fields have html embeded within so after some quick referencing, saw I can use the regExp function...
3
by: vonclausowitz | last post by:
Hi All, I was thinking of creating a table in my database to index all words in the database. That way I can quickly search for one or more words and the index table will return the words and...
49
by: Davy | last post by:
Hi all, I am writing a function, which return the pointer of the int. But it seems to be wrong. Any suggestion? int * get_p_t(int t) { return &t; } int main()
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.