@contextfilter
def group_by_letter(context, object_list):
 res = {}
 for x in object_list:
  r = re.search('^[a-zA-Z]', x.name)
  if r:
   key = r.group().lower()
   if (key not in res):
    res[key] = [x]
   else:
    res[key].append(x)
  n = re.search('^[0-9_]', x.name)
  if n:
   if ('#' not in res):
    res['#'] = [x]
   else:
    res['#'].append(x)
  if ((not n) and (not r)):
   if ('#' not in res):
    res['#'] = [x]
   else:
    res['#'].append(x)
 l = []
 for (k, v) in res.items():
  l.append((k, v))
  l.sort(cmp=(lambda x, y: cmp(x, y)))
 return l

@ contextfilter def group_by_letter ( context , object_list ) : res = { } for x in object_list : r = re . search ( '^[a-zA-Z]' , x . name ) if r : key = r . group ( ) . lower ( ) if ( key not in res ) : res [ key ] = [ x ] else : res [ key ] . append ( x ) n = re . search ( '^[0-9_]' , x . name ) if n : if ( '#' not in res ) : res [ '#' ] = [ x ] else : res [ '#' ] . append ( x ) if ( ( not n ) and ( not r ) ) : if ( '#' not in res ) : res [ '#' ] = [ x ] else : res [ '#' ] . append ( x ) l = [ ] for ( k , v ) in res . items ( ) : l . append ( ( k , v ) ) l . sort ( cmp = ( lambda x , y : cmp ( x , y ) ) ) return l
group contacts by letter .