[Tutor] iterating data and populating a dictionary
Monika Jisswel
monjissvel at googlemail.com
Tue Aug 5 17:43:41 CEST 2008
oops i forgot to count lines,
MainDictionary = {}
N = 0
M = 0
for line in open('data_file', 'r'):
if line:
if M < 3:
N += 1
M += 1
a, b = line.split(" = ") # "=" is in between spaces whish gives
you only two variables.
if a == 'Field':
MainDictionary[N] == {}
elif a == 'Index':
MainDictionary[N]['Value'] = {b}
else:
a, b = line.split(" = ") # "=" is in between spaces whish gives
you only two variables.
if a == 'Field':
MainDictionary[N] == {}
elif a == 'Index':
MainDictionary[N]['Value'] = {b}
M = 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080805/94ba6c13/attachment.htm>
More information about the Tutor
mailing list