'Determining validity of key
new to python and trying to think up how to approach having a list of valid characters allowed for a key within my dictionary.This key can be any combination of the characters all the way down to a single character or empty.
For example:
allowedWalkingDirection['N','n,'S','s','E','e','W','w']
def isRotateValid(path):
if allowedWalkingDirection in path['walk']:
return path
return False
And so if I try say: {'rotate':'WeNsE'} my input says it isn't valid. I'm sorry if this isn't very clear and concise, in short, my goal is to allow the valid walking directions to be input however many times within my key, but it's currently only allowing one character in the string.
Solution 1:[1]
ok, upon further brain melting and relentless internet perusing I've found some help from Valid characters in a String , I then thought of implementing something like
def isRotateValid(path):
for i in range(0,(len(path['walk']))):
if path['walk'][i] not in allowedWalkingDirection:
return False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | waterygatorade |
