We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4151e18 commit 984975dCopy full SHA for 984975d
4 - observer pattern/api_v2/event.py
@@ -1,8 +1,9 @@
1
-subscribers = dict()
+from collections import defaultdict
2
+
3
+# Default value of the dictionary will be list
4
+subscribers = defaultdict(list)
5
6
def subscribe(event_type: str, fn):
- if not event_type in subscribers:
- subscribers[event_type] = []
7
subscribers[event_type].append(fn)
8
9
def post_event(event_type: str, data):
0 commit comments