Before training a model, a dataset is cut into three consecutive parts: a training part, a validation part and a test part. Write three_way_split(data, train_pct, val_pct) that returns the tuple (train, val, test):
trainholds the firstlen(data) * train_pct // 100items,valholds the nextlen(data) * val_pct // 100items,testholds everything that is left.
The order of the items is kept, every item lands in exactly one part, and data itself must not be changed.
Examples
Input: data = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], train_pct = 60, val_pct = 20
Output: ([10, 11, 12, 13, 14, 15], [16, 17], [18, 19])
Input: data = ["a", "b", "c"], train_pct = 50, val_pct = 50
Output: (["a"], ["b"], ["c"])
Explanation: 3 * 50 // 100 = 1 for training and 1 for validation; the last item is left for testing.
Constraints
0 <= len(data) <= 10**50 <= train_pct, val_pctandtrain_pct + val_pct <= 100
Goals
- Cut a list into consecutive parts with slices
- Use one cut position as the stop of one slice and the start of the next
- Compute sizes with integer arithmetic so no floating-point rounding creeps in