Predict the output
What does this print?
print("/a//b/./../c/".split("/"))Choose an answer, then open Show answer below to check it.
Show answer
Answer: A ['', 'a', '', 'b', '.', '..', 'c', '']
Right: each slash splits, so repeated and trailing slashes give empty strings.
Empty strings from the split are just skipped by the stack walk, which is why splitting is the easy first step.
Why not the others?
- B ['a', 'b', '.', '..', 'c']. split keeps empty strings between neighbouring slashes.
- C ['/a', '/b', '/.', '/..', '/c']. The separator is removed, not kept.