Membership Operator Blocklist Check

Easy ⏱ 8 min 77% acceptance ★★★★☆ 4.3
Write a function is_allowed(username, blocklist) that returns False if username appears in the list blocklist, and True otherwise, using the in / not in membership operators (not a manual loop).

Examples

Example 1
Input
is_allowed("spammer1", ["spammer1", "bot99"])
Output
False
Explanation

"spammer1" is in the blocklist.

Example 2
Input
is_allowed("real_user", ["spammer1", "bot99"])
Output
True
Explanation

"real_user" is not blocked.

Constraints

  • blocklist is a list of strings, possibly empty.

Topics

Operatorsmembership operators

Companies

UberAirbnbSwiggy

Hints

Hint 1

`username not in blocklist` is exactly the membership test needed.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.