+ res_pllist = {}
+ for items in devs:
+ # The dict has some elements
+ if len(res_pllist) != 0:
+ # If the dict already has the key we append the new value
+ if items.classname in res_pllist.keys():
+ list = []
+ list = res_pllist[items.classname]
+ list.append(items['DeviceID'])
+ res_pllist[items.classname] = list
Couldn't these 4 lines be replaced by:
res_pllist[items.classname].append(items['DeviceID'])?
+ else:
+ # If the dict is not empty, but does not yet contain
+ # items.classname, we create new item
+ res_pllist[items.classname] = [items['DeviceID']]
This whole for loop can be replaced by:
for items in devs:
if items.classname in res_pllist.keys():
res_pllist[items.classname].append(items['DeviceID'])
else:
res_pllist[items.classname] = [items['DeviceID']]
You don't need to handle a separate case for when the dict has len() ==
0 because items.classname definitely won't be in the dict if the dict is
empty.
Thanks for adding these extra checks!
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin(a)linux.vnet.ibm.com