Replacing words from strings except 'and' / 'or' / 'and not'
Peter Maas
peter at somewhere.com
Fri Nov 26 03:26:55 EST 2004
Diez B. Roggisch schrieb:
> 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()])
Is there a reason to use sets here? I think lists will do as well.
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
More information about the Python-list
mailing list