def unread_handler(things, user, unread):
 sr_messages = collections.defaultdict(list)
 comments = []
 messages = []
 for thing in things:
  if isinstance(thing, Message):
   if getattr(thing, 'sr_id', False):
    sr_messages[thing.sr_id].append(thing)
   else:
    messages.append(thing)
  else:
   comments.append(thing)
 if sr_messages:
  mod_srs = Subreddit.reverse_moderator_ids(user)
  srs = Subreddit._byID(sr_messages.keys())
 else:
  mod_srs = []
 with CachedQueryMutator() as m:
  for (sr_id, things) in sr_messages.items():
   set_unread(things, user, unread, mutator=m)
   if (sr_id in mod_srs):
    sr = srs[sr_id]
    set_sr_unread(things, sr, unread, mutator=m)
  if comments:
   set_unread(comments, user, unread, mutator=m)
  if messages:
   set_unread(messages, user, unread, mutator=m)

def unread_handler ( things , user , unread ) : sr_messages = collections . defaultdict ( list ) comments = [ ] messages = [ ] for thing in things : if isinstance ( thing , Message ) : if getattr ( thing , 'sr_id' , False ) : sr_messages [ thing . sr_id ] . append ( thing ) else : messages . append ( thing ) else : comments . append ( thing ) if sr_messages : mod_srs = Subreddit . reverse_moderator_ids ( user ) srs = Subreddit . _byID ( sr_messages . keys ( ) ) else : mod_srs = [ ] with CachedQueryMutator ( ) as m : for ( sr_id , things ) in sr_messages . items ( ) : set_unread ( things , user , unread , mutator = m ) if ( sr_id in mod_srs ) : sr = srs [ sr_id ] set_sr_unread ( things , sr , unread , mutator = m ) if comments : set_unread ( comments , user , unread , mutator = m ) if messages : set_unread ( messages , user , unread , mutator = m )
given a user and things of varying types .