Page 1 of 1

Split list into chunks?

Posted: 04 Nov 2019 03:00
by Bluscre
I have a list of all user apps on the device and i'm currently looping over it and executing

Code: Select all

am force-stop <package>
for each item. The problem with that is that even with command timeout set to 1 it's really slow (takes over 2 mins to kill all)

My question is if there's a way (or even better a built in function) to split the list into chunks.

For example the list has 100 items and when i would do

Code: Select all

lists = splitChunks(list, 2);
list1 = lists[0];
list2 = lists[1];
it would return a list containing 2 lists with 50 items each that i can then go through in parallel to speed up the processing

Re: Split list into chunks?

Posted: 05 Nov 2019 18:09
by Desmanto
Why don't just loop over the original list based on the length and the output it to another list.

Code: Select all

lists = newList("Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot");

list1 = newList();
for(i in [0 to length(lists)/2 - 1])
  addElement(list1, lists[i]);
list2 = removeAllElementValues(lists, list1)
BTW, I don't think paralleling up the command can speed it up significantly. But I am curious to see the result.