<s> from collections import defaultdict <EOL> from pprint import pprint <EOL> def print_report ( target_dict , key = None ) : <EOL> len_pairs = len ( target_dict ) <EOL> print '<STR_LIT>' . format ( len_pairs ) <EOL> print <EOL> lenio_count_map = defaultdict ( int ) <EOL> for k , v in target_dict . iteritems ( ) : <EOL> lenio_count_map [ ( len ( k ) , len ( v ) ) ] += <NUM_LIT:1> <EOL> total_count = sum ( lenio_count_map . itervalues ( ) ) <EOL> print '<STR_LIT>' <EOL> print <EOL> cum_pct = <NUM_LIT> <EOL> for lenio , count in sorted ( lenio_count_map . iteritems ( ) , key = key ) : <EOL> pct = <NUM_LIT> * count / total_count <EOL> cum_pct += pct <EOL> print '<STR_LIT>' . format ( lenio , count , pct , cum_pct ) <EOL> print <EOL> print '<STR_LIT>' . format ( total_count ) <EOL> print '<STR_LIT>' . format ( <NUM_LIT:1.> * total_count / len ( lenio_count_map ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from time import time <EOL> start = time ( ) <EOL> import zipcodetw <EOL> end = time ( ) <EOL> print '<STR_LIT>' . format ( end - start ) <EOL> print <EOL> print '<STR_LIT>' <EOL> print <EOL> print_report ( zipcodetw . _dir . tokens_rzpairs_map ) <EOL> print <EOL> print <EOL> print '<STR_LIT>' <EOL> print <EOL> print_report ( zipcodetw . _dir . tokens_gzipcode_map , key = lambda p : ( p [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - p [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) ) </s>
