Created
August 31, 2015 18:03
-
-
Save neuman/ba234ecdb5a6a04975b8 to your computer and use it in GitHub Desktop.
Test Code
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
class EmbeddedMixin(object): | |
def get_embedded(self, hierarchy, key, value, depth=0, indexes=False): | |
index = 0 | |
domain = hierarchy.pop(0) | |
if len(hierarchy) == 0: | |
for embedded in self[domain]: | |
if embedded[key] == value: | |
if indexes == True: | |
return [index] | |
else: | |
return embedded | |
index += 1 | |
else: | |
for embedded in self[domain]: | |
output = embedded.get_embedded(hierarchy, key, value, depth=depth + 1, indexes=indexes) | |
if output != None: | |
if indexes == True: | |
output.insert(0, index) | |
return output | |
else: | |
return output | |
index += 1 | |
hierarchy.insert(0, domain) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment