def get_forums(query_result, user):
 it = itertools.groupby(query_result, operator.itemgetter(0))
 if user.is_authenticated:
  for (key, value) in it:
   forums = (key, [(item[1], item[2]) for item in value])
 else:
  for (key, value) in it:
   forums = (key, [(item[1], None) for item in value])
 return forums

def get_forums ( query_result , user ) : it = itertools . groupby ( query_result , operator . itemgetter ( 0 ) ) if user . is_authenticated : for ( key , value ) in it : forums = ( key , [ ( item [ 1 ] , item [ 2 ] ) for item in value ] ) else : for ( key , value ) in it : forums = ( key , [ ( item [ 1 ] , None ) for item in value ] ) return forums
returns a tuple which contains the category and the forums as list .