#NEWLINE# def parse( dataset ) : #NEWLINE# #INDENT# shapes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# with codecs . open ( dataset , 'r' , encoding = 'utf8' ) as dataset : #NEWLINE# #INDENT# current_char = '' #NEWLINE# current_shape = [ ] #NEWLINE# remaining_strokes = 1 #NEWLINE# for l in dataset . readlines ( ) : #NEWLINE# #INDENT# letter = letter_re . search ( l ) #NEWLINE# if letter : #NEWLINE# #INDENT# current_char = letter . group ( 'char' ) #NEWLINE# continue #NEWLINE# #UNINDENT# strokes = strokes_re . search ( l ) #NEWLINE# if strokes : #NEWLINE# #INDENT# remaining_strokes = int ( strokes . group ( 'nb' ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# points = points_re . search ( l ) #NEWLINE# if points : #NEWLINE# #INDENT# if ( remaining_strokes == 0 ) : #NEWLINE# #INDENT# raise RuntimeError ( 'I should not find points! No stroke is missing' ) #NEWLINE# #UNINDENT# remaining_strokes -= 1 #NEWLINE# current_shape . append ( map ( int , points . group ( 'coords' ) . split ( ) ) ) #NEWLINE# if ( remaining_strokes == 0 ) : #NEWLINE# #INDENT# shapes . setdefault ( current_char , [ ] ) . append ( remaining_strokes ) #NEWLINE# current_shape = [ ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return shapes