def chars_data(container, book_locale, *args): cc = count_all_chars(container, book_locale) nmap = {n:i for i, (n, l) in enumerate(container.spine_names)} def sort_key(name): return nmap.get(name, len(nmap)), numeric_sort_key(name) for i, (codepoint, usage) in enumerate(iteritems(cc.chars)): yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), cc.counter[codepoint])
def chars_data(container, book_locale, *args): cc = count_all_chars(container, book_locale) nmap = {n: i for i, (n, l) in enumerate(container.spine_names)} def sort_key(name): return nmap.get(name, len(nmap)), numeric_sort_key(name) for i, (codepoint, usage) in enumerate(iteritems(cc.chars)): yield Char(i, safe_chr(codepoint), codepoint, sorted(usage, key=sort_key), cc.counter[codepoint])