Replacing words from strings except 'and' / 'or' / 'and not'

Diez B. Roggisch deetsNOSPAM at web.de
Thu Nov 25 10:01:24 EST 2004


import sets
KEYWORDS = sets.Set(['and', 'or', 'not'])

query = "test and testing and not perl or testit or example"

def decorate(w):
    if w in KEYWORDS:
        return w
    return "*%s*" % w

query = " ".join([decorate(w.strip()) for w in query.split()])

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list