Skip to content

Commit 8e2f3ce

Browse files
committed
Used list imported from typing to specify the type of the items in the list
1 parent c172120 commit 8e2f3ce

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

prep exercises/generic_exercise.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from dataclasses import dataclass
2+
from typing import List
3+
4+
@dataclass(frozen=True)
5+
6+
class Person:
7+
name: str
8+
children: List["Person"]
9+
age: int
10+
11+
fatma = Person(name="Fatma", children=[], age=25)
12+
aisha = Person(name="Aisha", children=[], age = 15)
13+
14+
imran = Person(name="Imran", children=[fatma, aisha], age = 40)
15+
16+
def print_family_tree(person: Person) -> None:
17+
print(person.name)
18+
19+
for child in person.children:
20+
print(f"- {child.name} ({child.age})")
21+
22+
print_family_tree(imran)

0 commit comments

Comments
 (0)