Don't talk too much, just go to the code , It can be copied and run directly
def bisector_list(tabulation:list,num:int): """ Divide the list evenly into several parts :param tabulation:
list :param num: Number of copies :return: Returns a new list """ new_list = [] ''' The length of the list is greater than or equal to the number of copies ''' if len(
tabulation)>=num: '''remainder: List length divided by copies , Take the remainder ''' remainder = len(tabulation)%num if
remainder== 0: '''merchant: List length divided by score ''' merchant = int(len(tabulation) / num)
''' Split the list equally ''' for i in range(1,num+1): if i == 1: new_list.append(tabulation[:
merchant]) else: new_list.append(tabulation[(i-1)*merchant:i*merchant]) return
new_listelse: '''merchant: List length divided by score Take business ''' merchant = int(len(tabulation)//num)
'''remainder: List length divided by copies , Take the remainder ''' remainder = int(len(tabulation) % num) ''' Split the list equally '''
for i in range(1, num + 1): if i == 1: new_list.append(tabulation[:merchant])
else: new_list.append(tabulation[(i - 1) * merchant:i * merchant])
''' Add the remaining data to the previous list ''' if int(len(tabulation)-i*merchant)<=merchant: for j in
tabulation[-remainder:]: new_list[tabulation[-remainder:].index(j)].append(j)
return new_list else: ''' If the length of the list is less than the number of copies ''' for i in range(1, len(tabulation) + 1):
tabulation_subset= [] tabulation_subset.append(tabulation[i - 1]) new_list.
append(tabulation_subset) return new_list if __name__ == '__main__': a = [1,2,3,
4,5,6,7,8,9] x = bisector_list(a,4) print(x)
Technology