← 返回题库
中级

实现数组元素验证

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    raw_requests_csv = open_url(____).read()
    import json
    VALID_SKUS = {'____','____','____','____','____','____','____','____','____','____','____','____'}
    def validate_items_array(____):
        errors = []
        for i, item in enumerate(____):
            if not isinstance(____): errors.append(____); continue
            if '____' not in item: errors.append(____)
            elif item['____'] not in VALID_SKUS: errors.append(____)
            if '____' not in item: errors.append(____)
            elif not isinstance(____) or item['____'] < ____: errors.append(____)
        return errors
    test_arrays = [
        [{'____':'____','____':____},{'____':'____','____':____}],
        [{'____':'____','____':____},{'____':'____','____':____}],
        [{'____':'____','____':____},{'____':____}],
    ]
    for arr in test_arrays:
        errs = validate_items_array(____)
        print(____)

示例

输入
solve()
期望输出
items=['P001', 'P003']: VALID
items=['P999', 'P001']: ['[0]: invalid sku=P999', '[1]: invalid qty=0']
items=['P001', '?']: ['[1]: missing sku']
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码