Your current approach shuffles the list and then splits it into roughly equal portions. If you want to ensure that the sentences are divided into three arrays, even if they're not split equally, you can modify your code like this:
import random
import math
def split_sentences(sents):
random.shuffle(sents)
portion_size = math.ceil(len(sents) / 3)
return [sents[i:i + portion_size] for i in range(0, len(sents), portion_size)]
sents = ["sentence 1", "sentence 2", "sentence 3", "sentence 4"]
result = split_sentences(sents)
print(result)
This code will shuffle the list and then divide it into three groups. Since there are only 4 sentences, one of the arrays will have 2 sentences, while the other two will have 1 sentence each.
For example, the output might look like this (keep in mind that it's random):
[['sentence 3'], ['sentence 1', 'sentence 2'], ['sentence 4']]
This approach ensures that the sentences are divided into three arrays, even if they're not split equally.