Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
pass solution in Clear category for Simplify Unix Path by veky
def simplify_path(path):
segments = path.split('/')
absolute = not segments[0]
result = []
for segment in segments:
if '.'.startswith(segment): pass
elif segment != '..': result.append(segment)
elif result and result[~0] != '..': del result[~0]
elif not absolute: result.append(segment)
return '/'*absolute + '/'.join(result) or '.'
Aug. 1, 2017
Comments: