Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
6-liner: based on StefanPochmann's solution solution in Creative category for Simplify Unix Path by przemyslaw.daniel
def simplify_path(path):
is_abs, out = path.startswith('/'), []
for subdir in path.split('/'):
is_up = (is_abs or (out and out[-1] != '..')) and subdir == '..'
out = out[:-1] if is_up else out+[subdir]*(subdir not in '.')
return '/'*is_abs+'/'.join(out) or '.'
Aug. 10, 2017
Comments: