def add_to_pathvar(pathvarname, newpaths):
    envvar = os.environ.get(pathvarname, '')
    parts = [p for p in envvar.split(os.pathsep) if p.strip()]
    pset = set(parts)

    if isinstance(newpaths, basestring):
        entries = [p for p in newpaths.split(os.pathsep) if p.strip()]
    else:
        entries = newpaths

    for path in entries:
        if path not in pset:
            pset.add(path)
            parts.append(path)

    # remove any paths that don't exist
    final = [p for p in parts if p.startswith('.') or os.path.isdir(p)]

    return os.pathsep.join(final)
Return list reversed.
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.util/src/openmdao/util/lib.py/add_to_pathvar--crossover with--dataset/ETHPy150Open manahl/PythonTrainingExercises/Beginers/ListsTuples/solutions.py/select_reversed