Connecting Tech Pros Worldwide Forums | Help | Site Map

searching for matches within a word list

Rajarshi Guha
Guest
 
Posts: n/a
#1: Jul 18 '05
Hi,
I have a large list of words (each on its own line)
and I would like to find words that contain a specific string.

I have been trying to use a regexp but I cant see how I can find the
word that contained the regex pattern - all I get is the pattern itself
if I use match or findall.

I know that I could just go through the list line by line and see if the
regex matches or not - but that method seems horifically inefficient.

Does anybody have any suggestions as to how I could solve this
efficiently?

Thanks,
Rajarshi

Scott David Daniels
Guest
 
Posts: n/a
#2: Jul 18 '05

re: searching for matches within a word list


Rajarshi Guha wrote:[color=blue]
> Hi,
> I have a large list of words (each on its own line)
> and I would like to find words that contain a specific string.[/color]
How bad is (for 2.3)?
result = []
apnd = result.append
source = file('data', 'U')
for line in source:
if specific in line:
apnd(line)
source.close()
# result is the list you want

-Scott David Daniels
Scott.Daniels@Acm.Org

Closed Thread