#NEWLINE# @ solves ( q . group_by_key_func ) #NEWLINE# def group_by_key_func( iterable , key_func ) : #NEWLINE# #INDENT# result = collections . defaultdict ( list ) #NEWLINE# for item in iterable : #NEWLINE# #INDENT# result [ key_func ( item ) ] . append ( item ) #NEWLINE# #UNINDENT# return result