The "best" answers may use tricks not available when the boundary conditions are not well-defined.
In your example you say that "w, x, y, and z can be in list A", which does not specifically exclude a, b, or c. Whether or not this is important depends on context.
The question regarding whether the items are single values or lists may also have an impact.
Devs like to have fairly explicit requirements. The way to make it clearer is to make it clearer. Define boundary conditions explicitly. Provide typing information. Provide good/not-good examples. Etc.
Here's my spin, covering some edge cases, etc. with some followup afterwards.
How can I write a function that indicates if a list of values contains
only allowable values?
- Are "simple", e.g., no nested objects, tuples, etc.
- May be duplicated
- May appear in any order
- Are stored in a number of variables
allowable0 = "w"
allowable1 = "x"
allowable2 = "y"
allowable3 = "z"
# Should pass, contains only allowable values.
A = ["x", "y", "z"]
# Should pass, contains duplicate and repeated allowable values.
A = ["x", "x", "w", "z", "y"]
# Should fail, contains a value not in the allowable values.
A = ["a", "x", "z"]
The list does not need to contain all allowable values, it just
needs to only contain allowable values.
Compared with Daniel's, mine takes up significantly more vertical space. It covers a bit more ground with regards to specification, including some not asked for in the original–that was more an experiment in requirement density vs. readability.
[~DB/tech/communication]$ wc *
16 111 638 q1.txt
25 120 717 q2.txt
That was interesting; I enjoyed it.