Synchrony Interview Question

Group by function in python