if add_node:
nns_node = G.get_neighbors(node)
ego_nodes = [(rn, {"weight": w})for rn, w in nns_node.items()]
ego_network.add_nodes_from(ego_nodes)
else:
if "_" not in node: continue
After Change
ego_nn_nodes = []
for related_node, related_weight in G.get_neighbors(node).items():
if minimize(related_node) == minimize(ego): continue
ego_nn_nodes.append( (related_node, {"weight": related_weight}) )
ego_network.add_nodes_from(ego_nn_nodes)