def cleanFilePaths(file, listOfResults, type=None):
    """
    Constructs the data which consists of a dictionary within a dictionary.
    The first level has keys that are the data file name, and the second
    level contains two keys: saved and read. Within 'saved' and 'read'
    are a list that contains the scripts that either save or read
    the data file.

    Args:
        file (str): Path to a script that is being scanned
        listOfResults (list): List of strings of data files used in file
        type (string, optional): String to indicate if the list supplied
        contains saved datafiles or read data files. Defaults to None.

    Returns:
        dict : Dictionary of format described above
    """
    if type not in ['save', 'read']:
        raise ValueError(
            "Please specify whether or not listOfResults is"
            "'save' or 'read' list.")

    if not isinstance(listOfResults, list):
        raise ValueError(
            "Please provide a list to 'listOfResults'"
        )

    results = {}

    for dataFile in listOfResults:
        dataFile = dataFile.rsplit('/', 1)[-1]
        if dataFile not in results:
            results[dataFile] = {'save': [], 'read': []}
            results[dataFile][type].append(file.rsplit('/', 1)[-1])
        else:
            results[dataFile][type].append(file.rsplit('/', 1)[-1])

    return results