Complete the code to initialize the token bucket with the correct capacity.
token_bucket = {"capacity": [1], "tokens": 0, "rate": 5}The capacity defines the maximum number of tokens the bucket can hold. Here, it should be 10.
Complete the code to add tokens to the bucket without exceeding capacity.
token_bucket["tokens"] = min(token_bucket["tokens"] + [1], token_bucket["capacity"])
Tokens are added at the rate specified by token_bucket["rate"].
Fix the error in the code to check if enough tokens are available for a request.
if token_bucket["tokens"] >= [1]: token_bucket["tokens"] -= [1] allowed = True else: allowed = False
The code should check if the bucket has enough tokens for the requested amount, which is request_tokens.
Fill both blanks to create a dictionary comprehension that tracks tokens per user if tokens are above zero.
user_tokens = {user: [1] for user, tokens in token_data.items() if tokens [2] 0}The comprehension keeps users with tokens greater than zero and maps user to tokens.
Fill all three blanks to create a dictionary of users with tokens less than capacity and map user to tokens plus one.
updated_tokens = { [1]: [2] + 1 for [3], tokens in token_data.items() if tokens < token_bucket["capacity"] }The comprehension maps each user to their tokens plus one if tokens are less than capacity.