pythontwitterapi-pythontwitter-follow

create a pairs of users ids with python


I have two lists of users, early adopters and followers. I want to create a pair of users like

(early_adopter, follower). For example:

#in 
early_adopters = [1, 2, 3]

#out
follower_list = [(1,a),(1,b),(1,c),(2,a),(2,e),(3,f)]

In my code below, I can retrieve the follower list but this doesn't specify who follows whom.

follower_list = []
early_adopters = [1, 2, 3]

for usr in ea:
  for user in tweepy.Cursor(api.followers, user_id = usr).items():
    if user.id not in ea:
      follower_list.append(user.id)

Solution

  • You were very close:

    follower_list = []
    early_adopters = [1, 2, 3]
    
    for usr in early_adopters:
      for user in tweepy.Cursor(api.followers, user_id = usr).items():
        if user.id not in early_adopters:
          follower_list.append((usr, user.id))
    

    This stores a tuple of (early_adopter, follower) in the followers_list.