#NEWLINE# def _sketch2dict( sketch , brief = True ) : #NEWLINE# #INDENT# heavy_hitters = sketch . heavy_hitters ( ) #NEWLINE# if brief : #NEWLINE# #INDENT# heavy_hitters = dict ( sorted ( heavy_hitters . items ( ) , key = ( lambda e : e [ 1 ] [ 0 ] ) ) [ ( - 8 ) : ] ) #NEWLINE# #UNINDENT# heavy_hitters = dict ( [ ( repr ( k ) , [ v [ 0 ] , ( v [ 0 ] + heavy_hitters [ 1 ] ) ] ) for ( k , v ) in heavy_hitters . items ( ) ] ) #NEWLINE# return { #NEWLINE# #INDENT# 'n' : sketch . n , #NEWLINE# 'cardinality' : sketch . card ( ) , #NEWLINE# 'common_elements' : heavy_hitters , #NEWLINE# #UNINDENT# }