Add list_to_str fuction. Fix bugs in balance_partitions

Add list_to_str: covert sorted str list (sorted by cmpfun) to str value
(splited by sep).
Fix bugs in balance_partitions: bug occurs when left over bucket is
empty.