I'm trying to create a dictionary of word stems where the stems are the key and the value is the array of words that have the key as their stem. I've tried the following code
stem_word_dictionary = reduce(
lambda accumulator, word_stem_tuple:
accumulator.setdefault(word_stem_tuple[1], []).append(word_stem_tuple[0]),
word_stem_tuple_list,
{})
I get this error:
accumulator.setdefault(word_stem_tuple[1], []).append(word_stem_tuple[0]),
AttributeError: 'NoneType' object has no attribute 'setdefault'
I don't understand what's happening here. I'm using an empty dictionary as the starting value for the reduce so not sure why it's "NoneType". Also disclaimer: I'm super new to python.