"""This module contains code from Think Python by Allen B. Downey http://thinkpython.com Copyright 2012 Allen B. Downey License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html """ def read_dictionary(filename='c06d'): """Reads from a file and builds a dictionary that maps from each word to a string that describes its primary pronunciation. Secondary pronunciations are added to the dictionary with a number, in parentheses, at the end of the key, so the key for the second pronunciation of "abdominal" is "abdominal(2)". filename: string returns: map from string to pronunciation """ d = dict() fin = open(filename) for line in fin: # skip over the comments if line[0] == '#': continue t = line.split() word = t[0].lower() pron = ' '.join(t[1:]) d[word] = pron return d if __name__ == '__main__': d = read_dictionary() for k, v in d.items(): print k, v

AltStyle によって変換されたページ (->オリジナル) /