For a large list, such as a list of more than 10,000 elements, if you need to make a complex and time-consuming calculation of each element in the list, it is very slow to use single-threaded processing, it is necessary to use multi-threaded processing, before processing the first need to split the large list, split into a small list, Here's a way to write a split list of your own:
Each of these is the size of each list, and Len (LS)/eachexact avoids rounding down evenly, resulting in a reduction in the total number of groupings.
Note: The number of groupings is not a simple len (ls)/each +1, because it is possible to divide exactly, without the remainder.
1 defDivide (Ls,each):2dividedls=[]3eachexact=float (each)4Groupcount=len (LS)/ each5Groupcountexact=len (LS)/eachexact6start=07 forIinchxrange (groupcount):8Dividedls.append (ls[start:start+Each ])9start=start+ eachTen ifGroupcount<groupcountexact:#if the remainder, add all the remaining elements to the last group OneDividedls.append (ls[groupcount*Each :]) A returnDividedls
Python split list