<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def list_files(d, extension=None):
    '''
    Lists files in a given directory.

    Args:

        d (str): Path to a directory.

        extension (str): If supplied, only files that contain the
            specificied extension will be returned. Default is ``False``,
            which returns all files in ``d``.

    Returns:

        list: A sorted list of file paths.
    '''
    if os.path.isdir(d):
        expanded_dir = os.path.expanduser(d)
        files = sorted(glob.glob(expanded_dir + '/*'))
    else:
        files = [d, ]
    if extension is not None:
        if type(extension) in STR_TYPES:
            extension = [extension, ]
        files = [f for f in files if any([f.split('.')[-1] in extension,
                                          f.split('.')[-1].upper() in extension,
                                          f.split('.')[-1].lower() in extension])]
    return files