def build_vocab(data):
 counter = collections.Counter(data)
 count_pairs = sorted(counter.items(), key=(lambda x: ((- x[1]), x[0])))
 (words, _) = list(zip(*count_pairs))
 word_to_id = dict(zip(words, range(len(words))))
 return word_to_id

def build_vocab ( data ) : counter = collections . Counter ( data ) count_pairs = sorted ( counter . items ( ) , key = ( lambda x : ( ( - x [ 1 ] ) , x [ 0 ] ) ) ) ( words , _ ) = list ( zip ( * count_pairs ) ) word_to_id = dict ( zip ( words , range ( len ( words ) ) ) ) return word_to_id
build vocabulary .