What is Python?

Andrew Dalke dalke at acm.org
Tue Sep 19 13:51:07 EDT 2000


Alex Martelli wrote in message <8q74uu01npq at news1.newsguy.com>...
>"William Tanksley" <wtanksle at dolphin.openprojects.net>"
>> cat /scripts/movies/brian/* | grep "\\bjudea" | grep "\\bfront\\b"

>Non-re solutions would have a hard time with the word-boundary
>concept in general.

Nope.  In this case you aren't interested in the non-word characters,
so replace them with spaces.  Try

import string

from_str = string.join(map(str, range(0, 255)), "")
to_str = " " * ord("A") + \
         string.lowercase + \
         " " * (ord("_") - ord("Z")-1) + \
         "_ " + string.lowercase + \
         " " * (255 - ord("z"))

table = string.maketrans(from_str, to_str)

input = """\
The People's Front of Judea
The Judea People's Front
the PeopleFront of Judea
"""

for line in string.split(input, "\n"):
  words = string.split(string.translate(line, table))
  if "judea" in words and "front" in words:
    print line


                    Andrew
                    dalke at acm.org





More information about the Python-list mailing list