Skip to content

Commit 984975d

Browse files
author
Ujesh
committed
used default dict in api_v2/event instead of normal dict
1 parent 4151e18 commit 984975d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

4 - observer pattern/api_v2/event.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
subscribers = dict()
1+
from collections import defaultdict
2+
3+
# Default value of the dictionary will be list
4+
subscribers = defaultdict(list)
25

36
def subscribe(event_type: str, fn):
4-
if not event_type in subscribers:
5-
subscribers[event_type] = []
67
subscribers[event_type].append(fn)
78

89
def post_event(event_type: str, data):

0 commit comments

Comments
 (0)