Skip to content

Instantly share code, notes, and snippets.

@Shadow6363
Last active December 12, 2015 02:08
Show Gist options
  • Save Shadow6363/4696331 to your computer and use it in GitHub Desktop.
Save Shadow6363/4696331 to your computer and use it in GitHub Desktop.
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