def greedy_partition(counts, n):
 buckets = [[] for i in range(n)]
 fill_levels = [0 for i in range(n)]
 for key in sorted(counts, reverse=True, key=(lambda c: counts[c])):
  smallest = fill_levels.index(min(fill_levels))
  buckets[smallest].append(key)
  fill_levels[smallest] += counts[key]
 return (buckets, fill_levels)

def greedy_partition ( counts , n ) : buckets = [ [ ] for i in range ( n ) ] fill_levels = [ 0 for i in range ( n ) ] for key in sorted ( counts , reverse = True , key = ( lambda c : counts [ c ] ) ) : smallest = fill_levels . index ( min ( fill_levels ) ) buckets [ smallest ] . append ( key ) fill_levels [ smallest ] += counts [ key ] return ( buckets , fill_levels )
distribute k counts evenly across n buckets .