another list-dictionary question.
I have a dict as follows with unit names and testnames in a list:
dictA = {('unit1', 'test1'): 10, ('unit2', 'test1'): 78, ('unit2', 'test2'): 2, ('unit1', 'test2'): 45}
units = ['unit1', 'unit2']
testnames = ['test1','test2']
How do we find the max of the values for each test in testnames:
I tried as follows:
def max(dict, testnames_array):
maxdict = {}
maxlist = []
temp = []
for testname in testnames_array:
for (xunit, xtestname), value in dict.items():
if xtestname == testname:
if not isinstance(value, str):
temp.append(value)
temp = filter(None, temp)
stats = corestats.Stats(temp)
k = stats.max() #finds the max of a list using another module
maxdict[testname] = k
maxlist.append(maxdict)
maxlist.insert(0,{'Type':'MAX'})
return maxlist
Problem now is that im getting output:
[{'Type':'MAX'}, {'test1': xx}, {'test2':xx}]
where xx is all returned as a same values!!
where is my fault?
any simpler methods?
please advice. thanks.
I guess this should solve it.