def do_dictsort(value, case_sensitive=False, by='key'):
 if (by == 'key'):
  pos = 0
 elif (by == 'value'):
  pos = 1
 else:
  raise FilterArgumentError('You can only sort by either "key" or "value"')
 def sort_func(item):
  value = item[pos]
  if (isinstance(value, basestring) and (not case_sensitive)):
   value = value.lower()
  return value
 return sorted(value.items(), key=sort_func)

def do_dictsort ( value , case_sensitive = False , by = 'key' ) : if ( by == 'key' ) : pos = 0 elif ( by == 'value' ) : pos = 1 else : raise FilterArgumentError ( 'You can only sort by either "key" or "value"' ) def sort_func ( item ) : value = item [ pos ] if ( isinstance ( value , basestring ) and ( not case_sensitive ) ) : value = value . lower ( ) return value return sorted ( value . items ( ) , key = sort_func )
sort a dict and yield pairs .