Unfortunately, for me, I need to make a script backward compatible w/Python 2.4, and defaultdict doesn't exist in 2.4 version.
What can be an alternative for it?
The data structure for a given key is a list of:
[{'red': (12, 1, 12), 'white': (30, 2, 60), 'blue': (8, 1, 4), 'orange': (9, 4, 8), 'black': (10, 12, 4)}]
EDIT: Adding usage info. First I build the default dict with:
defDict[key1].append(... ...)
Then it's passed to several methods for key:val(list) lookups and key deletion.
Specifically for deletion:
if len(defDict[key1][0]) == 0:
del defDict[key1]
EDIT: error on NoneType
print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
print defDict[key]
print "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
if len(defDict[key][0]) == 0:
#del defDict[key]
Error:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
None
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
if len(defDict[key][0]) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'
I think the error comes from key:
print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
print defDict[key]
print "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
Output:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
None
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy