Your question is Count Characters and Find First. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
F5 BIG-IP diagnostics can contain compact log messages that need lightweight character analysis. Given a message and a target character, count every character in the message and return the target's first occurrence.
Implement a function that treats uppercase and lowercase characters as different characters and preserves every character, including spaces and punctuation.
The input consists of:
s, a string containing zero or more characters.target, a string containing exactly one character.Return a dictionary with:
counts: a dictionary mapping each character in s to its number of occurrences.first_index: the zero-based index of the first occurrence of target, or -1 if target does not appear.def analyze_string(s, target):