📘
Binary Vectorizer
Given a vocabulary list and a text, create a binary vector where each position is 1 if the corresponding vocabulary word appears in the text, and 0 otherwise.
Input format:
- Line 1: Comma-separated vocabulary words (already sorted)
- Line 2: The text to vectorize
All comparisons are case-insensitive.
Output: A list of 0s and 1s.
Example:
Input:
cat,dog,fish,the the cat sat
Output:
[1, 0, 0, 1]
Reasoning:
Step 1: Parse vocabulary ["cat", "dog", "fish", "the"]
Step 2: Check each vocab word in text "the cat sat" (lowered) contains: cat=yes, dog=no, fish=no, the=yes
Step 3: Build vector [1, 0, 0, 1]
Constraints:
- Vocabulary is provided comma-separated
- Case-insensitive matching
- Output: Python list of 0s and 1s
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.