blob: 26dd33b60f08c345eefb641c8682ca5118cfcc61 (
plain)
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
|
#!/opt/local/bin/python
#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004
#
#
# Run as: python ch-2.py < input-file
#
import fileinput
import getopt
import sys
#
# Parse options
#
opts, args = getopt . getopt (sys . argv [1:], 'f:')
for opt, val in opts:
if opt == "-f":
filename = val
#
# Find the words in 'filename' which can be constructed
# from the letters in 'letters'.
#
def find_words (filename, letters):
letters = list (letters . lower () . strip ())
for word in open (filename):
word = word . strip ()
copy = word . lower ()
for letter in letters:
copy = copy . replace (letter, "", 1)
if copy == "":
print (word)
for line in fileinput . input ('-'):
find_words (filename, line . strip ())
|