Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a0dcc730cb92a616f86f0bf Challenge 295: Schema Validator Part 1 29 challenge-295

--description--

Given an object (JavaScript) or dictionary (Python), determine if it matches the following schema:

{
  username: string
}
  • Extra keys are allowed

--hints--

is_valid_schema({"username": "bob"}) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": "bob"}), True)`)
}})

is_valid_schema({"username": "jen", "posts": 30}) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": "jen", "posts": 30}), True)`)
}})

is_valid_schema({"username": ""}) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": ""}), True)`)
}})

is_valid_schema({"username": 7}) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": 7}), False)`)
}})

is_valid_schema({"posts": 25}) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"posts": 25}), False)`)
}})

--seed--

--seed-contents--

def is_valid_schema(obj):

    return obj

--solutions--

def is_valid_schema(obj):
    return isinstance(obj.get("username"), str)