我在我的应用程序中建立了一个快速的部分,它可以查看用户的关注者,并突出显示用户关注的人(朋友)关注哪些人。在
我想知道两件事:
有没有更有效的方法?这似乎会超出Twitter的API限制,因为我需要检查每个用户朋友的好友。
这是在创建一个包含好友id和关注者的dict列表。相反,dict会更好地作为跟随者id,然后是跟随者的朋友。提示?
代码:
# Get followers and friends
followers = api.GetFollowerIDs()['ids']
friends = api.GetFriendIDs()['ids']
# Create list of followers user is not following
followers_not_friends = set(followers).difference(friends)
# Create list of which of user's followers are followed by which friends
followers_that_friends_follow = []
for f in friends:
ff = api.GetFriendIDs(f)['ids']
users = followers_not_friends.intersection(ff)
followers_that_friends_follow.append({'friend': f, 'users': users })
关于你问题的第二部分:
这将产生一个字典:
keys=ids跟随用户、用户不跟随的关注者以及用户的朋友跟随的追随者。在
values=跟随跟随者的朋友的id列表,用户没有跟随
例如,如果用户的跟随者的id为23,并且用户的两个朋友(用户16和用户28)跟随用户23,那么使用键23应该得到以下结果
^{pr2}$相关问题 更多 >
编程相关推荐