I have a dict where the keys map to arrays, like so:
{"A": [...], "B": [...], ...}
In a reducer function of mine I'd like to append to the value of a key, and set the key if it doesn't exist. Is there a clean way of doing this in a one-liner?
I was thinking of the following, JavaScript-style:
dict[key] = dict.get(key, []).append(val)
But forgot that .append doesn't return the list itself like a functional language would do. So the only way I see now is to have a dumb if loop check if the key exists, and create it if not... Is there a cleaner way? Thanks