-
Notifications
You must be signed in to change notification settings - Fork 0
/
pronounce.py
44 lines (31 loc) · 1.03 KB
/
pronounce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""This module contains a code example related to
Think Python, 2nd Edition
by Allen Downey
http://thinkpython2.com
Copyright 2015 Allen Downey
License: http://creativecommons.org/licenses/by/4.0/
"""
from __future__ import print_function, division
def read_dictionary(filename='c06d.txt'):
"""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)