def count_in(comments, user_id, ids, _in, _out): res = {} for comment in comments: _a = get_user_id_by_blog_id(comment.blog_id) _t = None if comment.reply_to: _comment = Comment.get(comment.reply_to) _t = get_user_id_by_author_id(_comment.author_id) _t = _t or _a if _t and _t <> user_id and _t in ids: _out[user_id] += 1 _in[_t] += 1 if _t in res: res[_t] += 1 else: res[_t] = 1 return res