0

My dictionary has to lists one of twitter user ID and one of screen names (harvested via tweepy.

Both lists are correct, but when I try to zip them into a dictionary the screen names wind up truncated.

an entry looks like this:

189754969: u'l'

the names do print out properly here is a sample:

AngelicaNUnga
JoeChevrette
sillyfaceee

here is the code that references the dictionary:

 def paginate(iterable, page_size):#functional but needed to make the other def work
     while True:
         i1, i2 = itertools.tee(iterable)
         iterable, page = (itertools.islice(i1, page_size, None),
            list(itertools.islice(i2, page_size)))
         if len(page) == 0:
             break
         yield page



 def get_followers(target):
      target_following_users = {}

      followers = []
      screen_n = []

      for page in tweepy.Cursor(api.followers_ids, screen_name=target).pages():#gets the followers for userID
          followers.extend(page)
          time.sleep(60)#keeps us cool with twitter

      for page in paginate(followers, 100):#see paginate 
          results = api.lookup_users(user_ids=page)
          for result in results:
                print result.screen_name
                screen_n.extend(result.screen_name)

      target_following_users.update(zip(followers, screen_n))

      return target_following_users

  print get_followers(target)

The issue seems to be in how I am creating my dictionary but I can't figure out why it is truncating. I would really like to use dictionaries for simplicity and not just return the two lists.

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
Kyle Sponable
  • 735
  • 1
  • 12
  • 31

1 Answers1

4

Without actually seeing this running, it appears you are extending the screen_n list with a list like this:

['u','s','e','r'] 

because the screen name is a string and you are using extend (which appends the items from the argument list to the list calling extend). You probably want screen_n.append(results.screen_name).

For example,

>>> a = range(3)
>>> a.extend(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> a.extend('45')
>>> a
[0, 1, 2, '4', '5']
Wyrmwood
  • 3,340
  • 29
  • 33