From 9d849a16ecdf8474c255bb2c671bc7c2ba93378b Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sun, 24 Feb 2019 02:28:42 +0100 Subject: [PATCH] Use defaultdict to for findHashId result --- src/Peer/Peer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Peer/Peer.py b/src/Peer/Peer.py index bcbf732b..81448187 100644 --- a/src/Peer/Peer.py +++ b/src/Peer/Peer.py @@ -2,6 +2,7 @@ import logging import time import sys import itertools +import collections import gevent @@ -311,7 +312,7 @@ class Peer(object): if not res or "error" in res or type(res) is not dict: return False - back = {} + back = collections.defaultdict(list) for ip_type in ["ipv4", "ipv6", "onion"]: if ip_type == "ipv4": @@ -319,8 +320,6 @@ class Peer(object): else: key = "peers_%s" % ip_type for hash, peers in res.get(key, {}).items()[0:30]: - if hash not in back: - back[hash] = [] if ip_type == "onion": unpacker_func = helper.unpackOnionAddress else: