I start with a long list, long let's say 4438. I need to create a list of sublists of that starting list. To do that, I have a list of indexes:
indexes = [0, 888, 1776, 2664, 3551, 4438]
This means, in my final list, the first sublist takes the first 888 elements, the second one the following 888, the third one the following 888 and so on.
What I need is the sublists to be:
sublist_1 = list_to_slice[0:888]
sublist_2 = list_to_slice[888:1776]
sublist_3 = list_to_slice[1776:2664]
...
My code:
final_list = [list_to_slice[i:i+1] for i in indexes]
The problem with my code is that instead of doing the above slicing, it does:
sublist_1 = list_to_slice[0:1]
sublist_2 = list_to_slice[888:889]
sublist_3 = list_to_slice[1776:1777]
...
That i+1
is deemed 'add 1 to the index i' instead of 'take the index that follows i', how can I get the code to do the latter? I need a fine piece of code that does this kind of slicing, I don't care if different to mine.