Finished
11from typing import Dict
2import re
23
34def count_words(sentence: str) -> Dict[str, int]:
4 pass
5 # Edge Case: Empty input string
6 if not sentence:
7 return {}
8
9 # Convert to lowercase for case insensitivity
10 sentence = sentence.lower()
11
12 # Find all sequences that qualify as words
13 # This includes alphanumeric sequences and contractions with apostrophes
14 words = re.findall(r"[a-z0-9]+(?:'[a-z0-9]+)*", sentence)
15
16 # Count occurrences of each word
17 word_count = {}
18 for word in words:
19 # Edge Case: Words with leading/trailing apostrophes (should be stripped by regex pattern)
20 # Edge Case: Empty words (handled by regex pattern)
21 word_count[word] = word_count.get(word, 0) + 1
22
23 # Edge Case: Very long strings (handled by implementation)
24 # Edge Case: Multiple consecutive whitespace characters (handled by regex pattern)
25 # Edge Case: Multiple consecutive punctuation marks (handled by regex pattern)
26 # Edge Case: Numbers mixed with letters (handled as valid words)
27 # Edge Case: Mixed case sensitivity handling (converted to lowercase)
28
29 return word_count
30# Handled Edge Cases: empty input strings, multiple consecutive whitespace characters, multiple consecutive punctuation marks, mixed case sensitivity handling, numbers mixed with letters, very long strings
Test NameStatus
test_alternating_word_separators_not_detected_as_a_word
Pass
test_count_one_of_each_word
Pass
test_count_one_word
Pass
test_handles_cramped_lists
Pass
test_handles_expanded_lists
Pass
test_ignore_punctuation
Pass
test_include_numbers
Pass
test_multiple_apostrophes_ignored
Pass
test_multiple_occurrences_of_a_word
Pass
test_multiple_spaces_not_detected_as_a_word
Pass
test_non_alphanumeric
Pass
test_normalize_case
Pass
test_quotation_for_word_with_apostrophe
Pass
test_substrings_from_the_beginning
Pass
test_tabs
Pass
test_with_apostrophes
Pass
test_with_quotations
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.