In Perl, I can iterate over a csv file and update an array pointed to by a key of a hash automagically. Suppose I had a file like this:
foo,1
foo,2
bar,3
baz,2
baz,1
baz,5
Then I can loop like this (pseudo-code):
for ($key,$val in csv file) {
push($hash{$key}, $val)
}
Such that I end up with a structure like this:
$hash = {
foo : [1,2]
bar : [3]
baz : [2, 1, 5]
}
What is the Pythonic way to accomplish the same?