easy +8 pts

Parse bullet list

Extract text items from markdown-style bullet lists, handling nested indentation and various bullet symbols.

Write a function `parse_bullets(text: str) -> list[str]` that takes a multi-line string containing a simple bullet list and returns a list of the bullet item texts in the order they appear. A line is considered a bullet item if it starts with optional leading spaces, followed by one of the bullet markers `-`, `*`, or `+`, then a space, then the item text. The item text is everything after the marker and the space. Your function should: - Process only the lines that are bullet items. - Ignore any non-bullet lines (including blank lines, headers, plain text, etc.). - Strip leading/trailing whitespace from each extracted item text. - Preserve the original order of the bullet items. - If a line has extra spaces before the bullet marker, they should be ignored (i.e., the marker can be indented). - Lines that have a bullet marker but no following space before the text are NOT bullet items (e.g., `-item` should be ignored). - A bullet marker at the end of a line (with no text) is NOT a valid bullet item (it should be ignored). Example: ``` - first item * second item + third item ``` returns `["first item", "second item", "third item"]`. Implement the function in the code editor. Do not use external libraries.

Constraints

Input `text` is a string with at most 1000 characters. The output list should contain at most 100 items. The function must run in O(n) time where n is the length of the input.

Example

>>> parse_bullets("- apple\n* banana\n+ cherry")
['apple', 'banana', 'cherry']

>>> parse_bullets("# Heading\n- first item\n\nSome text\n- second item")
['first item', 'second item']

>>> parse_bullets("- item with spaces   ")
['item with spaces']
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `str.splitlines()` to handle a multi-line string.
Check if the line after stripping leading spaces matches the pattern of a bullet marker followed by a space.
Use slicing or regular expressions to isolate the item text after the marker.
Remember to ignore lines that don't meet the criteria.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.