Guest User

Untitled

a guest
Jan 12th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. def followers_for_story(story):
  2.         topic_set = set(story['topic_list'])
  3.         author_key = story['author_key']
  4.  
  5.     # Group the author's followers by user_key                                                                                                                                  
  6.         followers = sorted(self.socialgraph.follower_set(author_key))
  7.     followers = groupby(followers,lambda x: x[0])
  8.  
  9.     # Iterate over each follower                                                                                                                                                
  10.         for follower_key, grouper in followers:
  11.             # Create a topic set for the follower                                                                                                                                    
  12.             follow_topic_set = set(topic for (_, topic) in grouper)
  13.  
  14.             # If any followed topic is in the story's topic_set,                                                                                                                    
  15.             # yield the follower_key                                                                                                                                                
  16.             if any((topic in topic_set) for topic in follow_topic_set):
  17.         yield follower_key
Add Comment
Please, Sign In to add comment