def test_read_dict(self): test_dict = read_dict() # Make sure every line has been processed (assumes CEDICT) lines_processed = sum([test_dict[x][0] for x in test_dict]) self.assertEqual(lines_processed, 104198) # Make sure entries have the right shape for key in test_dict: entry = test_dict[key] length = entry[0] self.assertEqual(len(entry), length + 1)
def print_definitions(words): """Print out the definitions of a set of words.""" cedict = read_dict() unknown_list = [] print("=" * 80) for word in words: try: for index, entry in enumerate(cedict[word]): if index is not 0: print("%s (%s) - %s" % (entry.traditional, entry.pinyin, entry.meaning)) print("=" * 80) except KeyError: unknown_list.append(word) print("%s Unknown words: %s" % (len(unknown_list), unknown_list))