<s> import sys <EOL> import fileinput <EOL> import itertools <EOL> ALPHABET = ( "<STR_LIT:A>" , "<STR_LIT:C>" , "<STR_LIT>" , "<STR_LIT:T>" ) <EOL> def sequence_count ( string , wordlength ) : <EOL> """<STR_LIT>""" <EOL> i = <NUM_LIT:0> <EOL> wc = { } <EOL> while i < len ( string ) - wordlength + <NUM_LIT:1> : <EOL> word = string [ i : i + wordlength ] <EOL> if word in wc : <EOL> wc [ word ] += <NUM_LIT:1> <EOL> else : <EOL> wc [ word ] = <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> return wc <EOL> def pretty_print ( wordcount_dict , wordlength ) : <EOL> """<STR_LIT>""" <EOL> output = "<STR_LIT>" <EOL> e = <NUM_LIT:0> <EOL> for w in itertools . product ( ALPHABET , repeat = wordlength ) : <EOL> w = '<STR_LIT>' . join ( w ) <EOL> try : <EOL> output += "<STR_LIT>" % ( e , wordcount_dict [ w ] ) <EOL> except IndexError : <EOL> output += "<STR_LIT>" <EOL> e += <NUM_LIT:1> <EOL> return output <EOL> def histogram ( filename , wordlength ) : <EOL> """<STR_LIT>""" <EOL> wc = { } <EOL> for line in open ( filename ) . readlines ( ) : <EOL> wcnew = sequence_count ( line , wordlength ) <EOL> wc = { i : wc . get ( i , <NUM_LIT:0> ) + wcnew . get ( i , <NUM_LIT:0> ) for i in set ( wc ) | set ( wcnew ) } <EOL> return pretty_print ( wc , wordlength ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print histogram ( sys . argv [ <NUM_LIT:1> ] , <NUM_LIT:3> ) </s>
