Reputation: 121
Solaris python 2.4.3:
from collections import defaultdict
does not exist..
Please advise what could be an alternative to use multi-level dictionaries:
dictOut['1']['exec'] = 'shell1.sh'
dictOut['1']['onfailure'] = 'continue'
...
dictOut['2']['exec'] = 'shell2.sh'
dictOut['2']['onfailure'] = stop'
many thanks applom
Upvotes: 2
Views: 4473
Reputation: 82924
Answered with looks-like-it-works code within the last 24 hours (found by searching for "defaultdict", choose "newest" or "active" order)
Upvotes: 2
Reputation: 5555
I just wonder why not to use single level dict with tuple as hash key?
Upvotes: 0
Reputation: 28753
As an alternative to setdefault
, if you want extra level of dictionary goodness, try
class MultiDict(dict):
def __getitem__(self, item):
if item not in self.iterkeys():
self[item] = MultiDict()
return super(MultiDict, self).__getitem__(item)
Upvotes: 2