diff options
| author | David Schwartz <dms061@bucknell.edu> | 2021-05-09 23:43:21 -0400 |
|---|---|---|
| committer | David Schwartz <dms061@bucknell.edu> | 2021-05-09 23:43:21 -0400 |
| commit | 970bc5a3fdc095df0fef63e1bd6852e3f734fd21 (patch) | |
| tree | 1f5466cb45fd4052f66af37d7ca462aab1bae50b /challenge-111/dms061/python3 | |
| parent | 4232aebd7e3139b12e9a9a0b389426345fb8211a (diff) | |
| download | perlweeklychallenge-club-970bc5a3fdc095df0fef63e1bd6852e3f734fd21.tar.gz perlweeklychallenge-club-970bc5a3fdc095df0fef63e1bd6852e3f734fd21.tar.bz2 perlweeklychallenge-club-970bc5a3fdc095df0fef63e1bd6852e3f734fd21.zip | |
Challenge 111 done
Diffstat (limited to 'challenge-111/dms061/python3')
| -rw-r--r-- | challenge-111/dms061/python3/ch-2.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-111/dms061/python3/ch-2.py b/challenge-111/dms061/python3/ch-2.py new file mode 100644 index 0000000000..e38ce33ef8 --- /dev/null +++ b/challenge-111/dms061/python3/ch-2.py @@ -0,0 +1,24 @@ +def sorted(arr): + for i in range(0, len(arr)-1, 1): + if(arr[i] > arr[i+1]): + return False + return True + +if __name__ == "__main__": + length = 0 + words = [] + with open("../perl/american-english", "r") as f: + for word in f.readlines(): + word = word.lower().strip() + #no need to scan for smaller words ;> + #I'm not sure that this saves any [noticable] amount of time + if(length < len(word) and sorted(word)): + if(len(word) > length): + length = len(word) + words = [word] + elif(len(word) == length): + words.append(word) + #else: we discard + print("Longest presorted word(s) is/are", length, "letters long") + print("Word(s):", words) + |
