0

I want to create a friends_list for each user ID in the usr list. This is what I have tried so far. I don't know how to call friends_list for each one or even all of them together in one list.

 def first_surface(friends):
     usr = ['298970145', '11922952', '17455195']

     for i in usr: 
    
         friends_list = []
    
         for user in tweepy.Cursor(api.friends, user_id = usr).items(15):
             friends_list.append(user.id)

  return

2 Answers 2

1

Does this work? it creates a list of the friends lists

 def first_surface(friends):
     usr = ['298970145', '11922952', '17455195']
     list_of_friends = []

     for i in usr:         
         friends_list = []        
         for user in tweepy.Cursor(api.friends, user_id = usr).items(15):
             friends_list.append(user.id)
         list_of_friends.append(friends_list)

  return list_of_friends

If you want to know the friends list for the first user, it would simply be list_of_friends[0]

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for replying, it wasn't what I was looking for. :)
1

I have got what I wanted with the code below:

friends_list = []

usr_all = ['298970145', '11922952', '17455195'];

for usr in usr_all:

  for user in tweepy.Cursor(api.friends, user_id = usr).items(15):
    friends_list.append(user.id)

However, I still don't know how to retrieve the friend_list for user 1 in the list for example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.