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

    Given the context in list format.
    Return the vocabulary, which is a dictionary for word to id.
    e.g. {'campbell': 2587, 'atlantic': 2247, 'aoun': 6746 .... }

    Parameters
    ----------
    data : list of str
        The context in list format

    Returns
    --------
    dictionary
        that maps word to unique ID. e.g. {'campbell': 2587, 'atlantic': 2247, 'aoun': 6746 .... }

    References
    ---------------
    - `tensorflow.models.rnn.ptb.reader <https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/rnn/ptb>`_

    Examples
    --------
    >>> data_path = os.getcwd() + '/simple-examples/data'
    >>> train_path = os.path.join(data_path, "ptb.train.txt")
    >>> word_to_id = build_vocab(read_txt_words(train_path))