forked from kyclark/tiny_python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution2_dict_comp.py
More file actions
executable file
·47 lines (34 loc) · 1.21 KB
/
solution2_dict_comp.py
File metadata and controls
executable file
·47 lines (34 loc) · 1.21 KB
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
45
46
47
#!/usr/bin/env python3
"""Lookup tables"""
import argparse
# --------------------------------------------------
def get_args():
"""get command-line arguments"""
parser = argparse.ArgumentParser(
description='Gashlycrumb',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('letter',
help='Letter(s)',
metavar='letter',
nargs='+',
type=str)
parser.add_argument('-f',
'--file',
help='Input file',
metavar='FILE',
type=argparse.FileType('r'),
default='gashlycrumb.txt')
return parser.parse_args()
# --------------------------------------------------
def main():
"""Make a jazz noise here"""
args = get_args()
lookup = {line[0].upper(): line.rstrip() for line in args.file}
for letter in args.letter:
if letter.upper() in lookup:
print(lookup[letter.upper()])
else:
print(f'I do not know "{letter}".')
# --------------------------------------------------
if __name__ == '__main__':
main()