-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_2.py
More file actions
30 lines (24 loc) · 833 Bytes
/
Problem_2.py
File metadata and controls
30 lines (24 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Person(object):
def __init__(self, first_name, last_name, father):
self.first_name = first_name
self.last_name = last_name
self.father = father
def __str__(self):
return "father"
L = []
def print_depth(d, depth=1):
if isinstance(d, dict):
for key, value in d.items():
L.append('{} {}'.format(key, depth))
if isinstance(value, object):
print_depth(value, depth=depth+1)
elif not isinstance(d, dict):
if isinstance(d, Person):
attributes = ["first_name", "last_name", "father"]
for att in attributes:
L.append('{} {}'.format(getattr(d, att), depth))
print_depth(d.father, depth+1)
return(L)
person_a = Person("first_name:","last_name:","father:")
person_b = Person("first_name:","last_name:",person_a)
D = {"key1":1, "key2":{"key3":1,"key4":{"key5":4, "user": person_b}}}