Makistos
4/20/2017 - 6:33 AM

Check if a string only has valid words. #python

Check if a string only has valid words. #python

import sys
 
valid_words = ('opsub', 'opequal', 'opadd', 'opmult', 'oprdiv', 'opidiv')
 
def is_valid(str):
    return all(word in valid_words for word in str.split())
 
not_validated = sys.argv[1]
 
if is_valid(not_validated):
    print "OK"
else:
    print "Fail"