Last active
December 12, 2015 02:08
-
-
Save Shadow6363/4696331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_requirement(requirement): | |
if isinstance(requirement, basestring): | |
return requirement is 'None' or requirement in board_configuration | |
if isinstance(requirement, dict): | |
if requirement.keys()[0] == 'and': | |
return all(check_requirement(requirement) for requirement in requirement['and']) | |
else: | |
return any(check_requirement(requirement) for requirement in requirement['or']) | |
if __name__ == '__main__': | |
board_configuration = [ | |
'Barometer', | |
'Rangefinder' | |
] | |
requirement = { | |
'and': [ | |
{ | |
'or': [ | |
'Barometer', | |
'rangefinder' | |
] | |
}, | |
{ | |
'or': [ | |
'barometer', | |
'rangefinder' | |
] | |
} | |
] | |
} | |
print check_requirement(requirement) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment