searching for matches within a word list

R

Rajarshi Guha

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
 
S

Scott David Daniels

Rajarshi said:
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.
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top