easy +10 pts

Parse path segments

Extract meaningful path segments from a URL-style string, ignoring empty parts and dots.

Write a function `parse_path_segments(path: str) -> list[str]` that takes a filesystem or URL path string and returns a list of its meaningful segments. Rules: - Split the path on forward slashes (`/`). - Ignore empty segments (e.g., leading, trailing, or repeated slashes). - Ignore segments that are exactly `.` (current directory). - Do NOT resolve `..` (parent directory) — keep them as literal segments. - The returned list must preserve the order of the remaining segments.

Constraints

path is a string with length 0 to 1000. It may contain any printable ASCII characters. The output list contains between 0 and 500 segments.

Example

>>> parse_path_segments('/home/user/docs/')
['home', 'user', 'docs']
>>> parse_path_segments('a//b/./c')
['a', 'b', 'c']
>>> parse_path_segments('./foo/../bar')
['foo', '..', 'bar']
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `split('/')` to break the path.
Filter out empty strings and '.' segments.
Keep '..' as a normal segment.
Remember to return a list, not a set or tuple.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.