Suggestions for how to approach this problem?

John Salerno johnjsal at NOSPAMgmail.com
Thu May 10 14:26:55 EDT 2007


James Stroud wrote:

> import re
> records = []
> record = None
> counter = 1
> regex = re.compile(r'^(\d+)\. (.*)')
> for aline in lines:
>   m = regex.search(aline)
>   if m is not None:
>     recnum, aline = m.groups()
>     if int(recnum) == counter:
>       if record is not None:
>         records.append(record)
>       record = [aline.strip()]
>       counter += 1
>     continue
>   record.append(aline.strip())
> 
> if record is not None:
>   records.append(record)
> 
> records = [" ".join(r) for r in records]

What do I need to do to get this to run against the text that I have? Is 
'lines' meant to be a list of the lines from the original citation file?



More information about the Python-list mailing list