[Tutor] Please help
Allen John Schmidt, Jr.
ajschmidt at fredericksburg.com
Wed Aug 3 17:01:09 CEST 2005
Hey, I had a similar problem not too long ago. My data came in the first
format, but I didn't need it formated like that.
Here is how I would have written it:
import re
col=re.compile('(AD.*?)\s*$')
datas=re.compile('\s*(.+?)\s+(.+?)')
f1 = open('xx','r')
mind={}
matching=''
for i in meat:
match=col.find(i)
if match:
mind[match.group(1)]=[]
matching=match.group(1)
match=datas.find(i)
if match:
mind[matching].append([match.group(1),match.group(2)])
That would collect the data and put it into a dictionary with the values
being a list of the two part data. You could print like this:
for each in mind.keys():
print each
for value in mind[each]:
print each+" "+value[0]+" "+value[1]
That should do it!
Ask if you don't understand any part of it.
Allen J. Schmidt, Jr.
More information about the Tutor
mailing list