aboutsummaryrefslogtreecommitdiff
path: root/challenge-004/abigail/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-07 08:27:30 +0000
committerGitHub <noreply@github.com>2021-03-07 08:27:30 +0000
commitfe1156ab62c8a5a8a1ee5cded3dd909dcc618365 (patch)
tree79149d2c37239d0633307a1f5f6e2b8e6a35c78c /challenge-004/abigail/python/ch-2.py
parent7a1c751b9c8acb2cbea989419907a72cfcba3642 (diff)
parent07d0ccdc3b3a291016a184219bb885bce49c5cd8 (diff)
downloadperlweeklychallenge-club-fe1156ab62c8a5a8a1ee5cded3dd909dcc618365.tar.gz
perlweeklychallenge-club-fe1156ab62c8a5a8a1ee5cded3dd909dcc618365.tar.bz2
perlweeklychallenge-club-fe1156ab62c8a5a8a1ee5cded3dd909dcc618365.zip
Merge pull request #3668 from Abigail/abigail/week-004
Abigail/week 004
Diffstat (limited to 'challenge-004/abigail/python/ch-2.py')
-rw-r--r--challenge-004/abigail/python/ch-2.py40
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 ())