How to Parse Bullet Points in Python

Extract bullet point items from raw text by splitting lines and filtering those that start with '- ' or '* '.

Easy Python 3.9+ Aug 9, 2026 Lists & loops 13 views 0 copies

Python code

26 lines
Python 3.9+
def parse_bullet_points(text):
    """Extract bullet point items from raw text."""
    lines = text.splitlines()
    items = []
    
    for line in lines:
        stripped = line.strip()
        if stripped.startswith("- ") or stripped.startswith("* "):
            item = stripped[2:]
            if item:
                items.append(item)
    
    return items


if __name__ == "__main__":
    sample_text = """Shopping List
- Apples
* Bananas
-  Oranges
  * Grapes (indented)
Regular line, not a bullet
-  """
    
    result = parse_bullet_points(sample_text)
    print(f"Found {len(result)} items: {result}")

Output

stdout
Found 4 items: ['Apples', 'Bananas', 'Oranges', 'Grapes (indented)']

How it works

The function uses splitlines() to get each line from the input text, then iterates over them with a for loop. After stripping whitespace, it checks if the line starts with a bullet marker (- or *). If so, it removes the first two characters (the marker and a space) and appends the item to the list. The conditional check if item filters out empty bullets, like a trailing - with only spaces. This pattern is efficient for simple text parsing without external libraries.

Common mistakes

  • Forgetting to handle indented bullets by using `strip()` before checking
  • Not removing the marker space, leaving extra whitespace in items
  • Assuming only one bullet style; missing lines that start with `* ` or other markers

Variations

  1. Use a list comprehension with a startswith condition to build the list in one line
  2. Add support for numbered lists by checking `re.match(r'\d+\.', line)`

Real-world use cases

  • Parsing markdown-style bullet lists from user notes to convert into structured tasks.
  • Extracting feature requests from plain-text ticket descriptions for workflow automation.
  • Reading configuration files that use bullet markers to define list-valued settings.

Sponsored

Run this sample

Open the browser IDE to tweak the example and see results without installing anything.

Open editor

More from Lists & loops

Related tutorials and quizzes for this topic.