473,791 Members | 3,193 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find all the same words in a text?

I need to find all the same words in a text .
What would be the best idea to do that?
I used string.find but it does not work properly for the words.
Let suppose I want to find a number 324 in the text

'45 324 45324'

there is only one occurrence of 324 word but string.find() finds 2
occurrences ( in 45324 too)

Must I use regex?
Thanks for help
L.

Feb 10 '07
10 3919
at************* @gmail.com on 11 Feb 2007 08:16:11 -0800 didst step
forth and proclaim thus:
More concisely:

import re

pattern = re.compile(r'\b 324\b')
indices = [ match.start() for match in
pattern.findite r(target_string ) ]
print "Indices", indices
print "Count: ", len(indices)
Thank you, this is educational. I didn't realize that finditer
returned match objects instead of tuples.
Cheers,
Steven
--
Sam Peterson
skpeterson At nospam ucdavis.edu
"if programmers were paid to remove code instead of adding it,
software would be much better" -- unknown
Feb 12 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2995
by: Gary | last post by:
Hello, Is it possible to dynamically update a textbox with words chosen from a list using form checkboxes and javascript? Gary
1
1683
by: t0M | last post by:
It's nearly impossible to find anything on this because of the Dictionary class, included within the dotnet framework, that pollutes any search results pertinent to my question. I want to be able to access an array of words, just like it were a physical dictionary. It's for a stupid little project, but it involves decryption. Is there a file that Word has which contains this collection of words that I can import somehow into my dotnet...
0
1633
by: SoftComplete Development | last post by:
AlphaTIX is a powerful, fast, scalable and easy to use Full Text Indexing and Retrieval library that will completely satisfy your application's indexing and retrieval needs. AlphaTIX indexing technology provides you with highest indexing performance, possibility to index very large sets of data in minimal time even with memory constraints and unbelievable fast query processing speed. The main AlphaTIX's feature that makes it first and...
5
7840
by: Paula | last post by:
Hi !! I have to find some words in a string. I can use string.IndexOf, LastIndexOf, etc, but they are case sensitive. And there is another problem : If I found the word, I have to get three words before and after the found word . Example:
2
1433
by: Raed Sawalha | last post by:
I have the following text:- Brian went to stadium to watch the soccer game, Brian MacWoods is bussiness man and very rich man. Brian likes to run every morning on beachside. the problem i have I get the list of words that should be replace in the provided text as follows:- Brian (ONLY) : should be replaced by Mr with Brian word itself==> will be
14
22582
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the first occurence. I want to know the positions of both "1234" thanks
7
1368
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, How can I implement regex to find complete or partial words or a group of words. Similar to the "Find" in MS Word. I need to scan text files eg look for "test" or "this is a test" or "this is a te" Thanks
8
2320
by: inFocus | last post by:
Hello, I am new to python and wanted to write something for myself where after inputing two words it would search entire drive and when finding both names in files name would either copy or move thoe files to a specified directory. But couple of attempts did not work as desired this is one of them. Could someone help fix it or maybe give a better example.
6
2283
by: jeddiki | last post by:
I am writing a little script that will improve authors writing skills by finding repeated phrases in the text. The text of a chapter will average about 10,000 words, however, I could reduce the size of the files if it is better to do so. So the idea is to search through a string and find repeats of any 3 or 4 word group. So if the author has repeated the phrase "then I went" 6 times in the text, then this would be found and...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.