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
""" | |
I use logic that use just node values, which is a bit simpler | |
""" | |
class Node(object): | |
def __init__(self, value, parentNode): | |
self.value = value | |
self.parent = parentNode |
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
""" | |
Design General model according example that is given. | |
The idea is to have item and characteristic models. | |
Where we can store characteristics such a RAM: 4gb and add to an Item. | |
""" | |
from django.db import models | |
class Characteristic(models.Model): |
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
from django.db import models | |
class Employee(models.Model): | |
name = models.CharField(max_length=50) | |
birth_day = models.DateField() | |
department = models.ForeignKey('Department') | |
class Department(models.Model): | |
sector = models.CharField(max_length=255) |
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 Node(object): | |
def __init__(self, value, parentNode): | |
self.value = value | |
self.parent = parentNode | |
# match node that has particular value | |
def match_node(ancs, matcher): | |
for node in ancs: | |
if matcher(node): | |
return node |
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 depth(dictionary, count=0): | |
count +=1 | |
# I use sorted for our case | |
# to print out as it's expected in the written task | |
# We should use OrderDict as input if it's required to keep the order of dict. | |
for key, value in sorted(dictionary.items()): | |
print key, count | |
if isinstance(value, dict): |