<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def listrecursive(path, ext=None):
 """ List files recurisvely """

    filenames = set()
    for root, dirs, files in os.walk(path):
        if ext:
            if ext == 'tif' or ext == 'tiff':
                tmp = fnmatch.filter(files, '*.' + 'tiff')
                files = tmp + fnmatch.filter(files, '*.' + 'tif')
            else:
                files = fnmatch.filter(files, '*.' + ext)
        for filename in files:
            filenames.add(os.path.join(root, filename))
    filenames = list(filenames)
    filenames.sort()
    return sorted(filenames)