I have a Python code that looks like:
if key in dict:
dict[key].append(some_value)
else:
dict[key] = [some_value]
but I figure there should be some method to get around this 'if' statement. I tried:
dict.setdefault(key, [])
dict[key].append(some_value)
and
dict[key] = dict.get(key, []).append(some_value)
but both complain about "TypeError: unhashable type: 'list'". Any recommendations?