gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: [Gnumed-devel] help with trimming $


From: Tim Churches
Subject: Re: Re: [Gnumed-devel] help with trimming $
Date: Tue, 01 Mar 2005 14:51:33 +1100

Horst Herb <address@hidden> wrote:
> 
> On Tue, 1 Mar 2005 14:05, Richard Terry wrote:
> > eg 10/12/2004 Hypertension to return just Hypertension
> > or 10/2000 Appendix
> > 0r 2001 Cancer Bowel to return Cancer of the bowel
> >
> > Anyone volunteer the python code to use.
> 
> For this I wouldn't even use regular expressions (which cost a lot of 
> processor time and memory)
> - all examples stated start with a number, so would just parse:
> if (line starts with number):
> 1.) read character until character not in [0-9, '.', '/', '-'] and 
> append to 
> parsestr
> 2.) try split parsestr with date separators ('.', '/', '-')
> 3.) if only one split str and length ==4: this is the date (check 
> plausibility 
> of date)
> 4.) else, if two split strings: assume first junk is months, last is 
> year, 
> check for plausibility
> 5.) else, ...
> 
> hey, it's quick and easy to do in Python, and since you are learning 
> Python 
> just now, ... a good exercise in string manipulation / parsing?

Am I correct in thinking you just want to keep everything after the first 
space? If so, 
one efficinet method is to split on spaces, and rejoin all but the first 
element:

mystring = " ".join(mystring.split()[1:])

Tim C




reply via email to

[Prev in Thread] Current Thread [Next in Thread]