All problems
Token Chunk Lengths
Problem
Split n_tokens tokens into consecutive chunks of chunk_size tokens.
Return the list of chunk lengths in order, with the final chunk shorter when the split is uneven. Return an empty list when n_tokens or chunk_size is not positive.
Hint
Take chunk_size tokens at a time and record what remains on the last slice.
Test cases
case 1
in: [10,4]
expected: [4,4,2]
case 2
in: [8,4]
expected: [4,4]
case 3
in: [5,10]
expected: [5]
case 4
in: [0,3]
expected: []
case 5
in: [7,2]
expected: [2,2,2,1]
Starter codePython
def token_chunk_lengths(n_tokens, chunk_size):
# Your code here
pass5 test cases · run your code against them in the editor