jweinst1
6/5/2015 - 12:59 AM

A function that takes a list and slices it into n segments, while sorting them into a dictionary of lists.

A function that takes a list and slices it into n segments, while sorting them into a dictionary of lists.

def divide_list(list, n):
	dividend = len(list) / n
	div_dict, div_list = {x:[] for x in range(dividend)}, []
	first_part, end_part = 0, n
	dic_index = 0
	while dic_index < max(div_dict.keys()) + 1:
		div_dict[dic_index].append(list[first_part:end_part])
		first_part = end_part
		end_part = end_part + end_part
		dic_index = dic_index + 1
	return div_dict