Your question is User Input Processing and Validation. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The monday Work Management API receives a batch of user-submitted item updates. Write a function that validates and normalizes the batch efficiently while preserving the order of accepted updates.
An update is valid when it is a dictionary containing item_id, column, and value where:
item_id is a positive integer, but booleans are not accepted.column is a string whose surrounding whitespace is removed, and whose normalized value appears in allowed_columns.value is a string whose surrounding whitespace is removed, is not empty, and has at most 100 characters.(item_id, column) pair. If a duplicate occurs, reject the later update.Return a dictionary with two fields: valid, containing normalized update dictionaries, and invalid_indices, containing the zero-based indices of every rejected update in input order. Invalid updates must not reserve their item-column pair.
def validate_updates(updates, allowed_columns):