Skip to content

Instantly share code, notes, and snippets.

View dusan87's full-sized avatar

Dusan Ristic dusan87

  • @Metro.Digital
  • Berlin
View GitHub Profile
"""
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
"""
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):
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)
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
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):