def t(x): physicals = [] free = [] total = [] type = [] for child in x.findall('Drive'): free.append(child.findall('Free_bytes')) total.append(child.findall('Total_bytes')) type.append(child.findall('Drive_type')) # combine list of free bytes with list of total bytes into one list of tuples [(free, total), (free, total)] pairs = zip([e[0].text for e in free],[f[0].text for f in total]) i = 0 for p in pairs: if type[i][0].text == '3': physicals.append(p) i += 1 return { "Free Space": physicals}