diff options
| author | boblied <boblied@gmail.com> | 2021-03-09 07:52:31 -0600 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2021-03-09 07:52:31 -0600 |
| commit | c897ab614e0a35455865bfe930df300bb854a03b (patch) | |
| tree | a6a3527b8364196045a94ab49661bd2eb9c8fea6 /challenge-004/abigail/python/ch-2.py | |
| parent | 199d363b79e769bf8dc150bf37228395bfbb4d16 (diff) | |
| parent | da7e149ecb3abdf29d3fb4f712427217d02f2fe1 (diff) | |
| download | perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.gz perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.bz2 perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-004/abigail/python/ch-2.py')
| -rw-r--r-- | challenge-004/abigail/python/ch-2.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-004/abigail/python/ch-2.py b/challenge-004/abigail/python/ch-2.py new file mode 100644 index 0000000000..4e94f7fe7d --- /dev/null +++ b/challenge-004/abigail/python/ch-2.py @@ -0,0 +1,40 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# 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 ()) |
