Your question is Find Character Counts and Conditional Sort. 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.
A Lam Research equipment test log contains a text string and a list of candidate tokens. Count every character in the text, including spaces and punctuation, with case sensitivity. Then sort the tokens by a frequency score.
For a token, its score is the sum of the text frequency of each character occurrence in that token. Sort tokens by descending score. If two tokens have the same score, sort them in ascending lexicographic order.
Implement count_and_sort(text, items).
text is a string.items is a list of strings.counts, a dictionary mapping each character in text to its count, and sorted_items, the reordered list of tokens.def count_and_sort(text, items):