human
Complete the below
def do_dictsort(value, case_sensitive=False, by='key'):

    ''''Sort a dict and yield (key, value) pairs. Because python dicts are
    unsorted you may want to use this function to order them by either
    key or value:
    .. sourcecode:: jinja
    {% for item in mydict|dictsort %}
    sort the dict by key, case insensitive
    {% for item in mydict|dictsort(true) %}
    sort the dict by key, case sensitive
    {% for item in mydict|dictsort(false, \'value\') %}
    sort the dict by key, case insensitive, sorted
    normally and ordered by value.'
    '''
 ... Give me a the Python code you requested?
assistant
#Here is the Python code you requested.
    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, string_types) and (not case_sensitive)):
            value = value.lower()
        return value
    return sorted(value.items(), key=sort_func)