python: refactor out split-apply-combine reduceby funcs

These will be used in spark
spark: by uses combineByKey, not groupByKey