aboutsummaryrefslogtreecommitdiff
path: root/challenge-111/stuart-little/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-111/stuart-little/python/ch-2.py')
-rwxr-xr-xchallenge-111/stuart-little/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-111/stuart-little/python/ch-2.py b/challenge-111/stuart-little/python/ch-2.py
new file mode 100755
index 0000000000..4b465407d6
--- /dev/null
+++ b/challenge-111/stuart-little/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+# run <script> <path-to-dict-file, one word per line>
+
+import sys
+
+def isSorted(wrd):
+ return wrd.isalpha() and all([wrd.lower()[i] <= wrd.lower()[i+1] for i in range(0,len(wrd)-1)])
+
+def longestWith(lst,pred):
+ lngth=0
+ res=[]
+ for wrd in lst:
+ if (not pred(wrd)):
+ continue
+ l=len(wrd)
+ if l > lngth:
+ lngth = l
+ res=[wrd]
+ continue
+ if l == lngth:
+ res.append(wrd)
+ return res
+
+with open(sys.argv[1]) as fh:
+ wrds=filter(lambda ln: len(ln) > 0, map(lambda ln: ln.strip(), fh.readlines()))
+
+for wrd in longestWith(wrds,isSorted):
+ print(wrd)