In Python, the defaultdict class provides a convenient way to create a mapping from key -> [list of values], in the following example,
defaultdict
key -> [list of values]
In Java 8+ you can use:
map.computeIfAbsent(1, k -> new ArrayList()).add(2);