I would break it down into steps. If I were doing it I might read it in as a list, then parse the elements of the list to create my dictionary.
mlist = []
newfile = open("comp.txt", "rt")
for item in newfile:
mlist.append(item)
print(mlist) Then just manipulate the text however you see fit, if every first item starts with comp that gives you a starting point. You could use some temporary lists to seperate they key from the other data. For example.
tmp1 = []
tmp2 = []
for item in mlist:
if "comp" in item:
tmp1.append(item[0:6]) '''assuming that the length doesn't change'''
else:
tmp2.append(item[9:len(item)])
I'm sure there are simpler ways but this should give you an idea of how to break it down into steps.
willygstyle
Junior Poster in Training
60 posts since Aug 2009
Reputation Points: 17
Solved Threads: 9