[Tutor] Paper Rock Scissors game - User's choice not returned properly
steve at pearwood.info
Fri Nov 4 02:42:30 CET 2011
Alan Gauld wrote:
> Use the list form, even though it does involve a few more keystrokes and
> a lot more screen space. The extra typing to avoid the problems are not
> worth it! :-)
If you're worried about the screen space and/or keystrokes, you can do this:
if direction.upper() in tuple('NSEW'): ...
if direction.upper() in ('N', 'S', 'E', 'W'): ...
You can also use list, set or frozenset instead of tuple., but I prefer
tuple because it signals the intention that the result should be read-only.
More information about the Tutor