[Tutor] about python function +reg expression

Michael Janssen Janssen@rz.uni-frankfurt.de
Sun Mar 23 05:33:01 2003


On Sat, 22 Mar 2003, Abdirizak abdi wrote:

> I am working on a fucnction that does the following:
>    the function takes a string as follows:
>        <EQN/>what it is in here<EQN/>   and
>        first it filters to get the middle part of the string:
>       as follows:---  what it is in here--- and then I want to tag each token
>       as follows:
>       <W>what</W> <W>it</W> <W>is</W> <W>in</W> <W>here</W>
>       and finally it returns:
>       <EQN/> <W>what</W> <W>it</W> <W>is</W> <W>in</W> <W>here</W> <EQN/>

your example doesn't say why you split away EQN than split words/ tokens
than reattache EQN. Perhaps inbetween are some functions that depends on
this behaviour but you will need to boost up my fantasy.

Why not split into tokens and conditionally put tags around?

> [' of a conditioned word '] ---> it extracts what I want that is fine
>
> my problem is how can I manipulate this so that I have a list to
> manipulate such as this [ 'of' ', 'a','conditioned', 'word' ] so that
> I tag with <W>....</W> by using a loop as mentioned above:
>
> I have also attached the EQNfunc.py with this e-mail for reference
>
> X.split()  doesn't work simply

You're getting empty results, right? One in front and one at the back,
right? Due to leading and trailing spaces, isn't it? Check out
string.strip .

Michael

>
> thanks in advance
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!