reading an array with multiple items (working on two items not three)
Code below reads from a text file (containing different arrays) and breaks
down into separate elements. I have it working fine with arrays with TWO
sub items, but not a third.
For example - This file works fine:
('January', 2, [('curly', 30), ('larry',10), ('moe',20)])
..
staff = dict()
for item in filecontent:
month = filecontent[0]
section = filecontent[1]
for name, hours in filecontent[2]:
staff[name] = hours
print ("month:" + month)
print ("section: " + str (section))
print ("".join("%s has worked %s hours\n" % (name, hours) for name, hours
in staff.items()))
overtime = int(input ("Enter overtime figure: "))
print ("".join("%s has now worked %s hours \n" % (name, (hours +
overtime)) for name, hours in staff.items()))
But I have a different month with a third array element (a bonus figure),
for example:
('February', 2, [('curly', 30, **10**), ('larry',10, **10** ), ('moe',20,
**10**)])
My attempt at adapting the above code is below, but not working...
staff = dict()
for item in filecontent:
month = filecontent[0]
section = filecontent[1]
for name, hours, bonus in filecontent[2]:
staff[name] = hours, bonus
print ("month:" + month)
print ("section: " + str (section))
print ("".join("%s has worked %s hours with %s bonus \n" % (name, hours,
bonus) for name, hours, bonus in staff.items()))
No comments:
Post a Comment