diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-10 05:59:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-10 05:59:03 +0100 |
| commit | b5c46736cd45e6d03497f841e2ebb0ee69b37d62 (patch) | |
| tree | 11b4f91143ea05b392a0653a5410a5f0311050fd /challenge-111/dms061/python3 | |
| parent | 4232aebd7e3139b12e9a9a0b389426345fb8211a (diff) | |
| parent | 9780a99c852d06152d3e255ffda0f162fbb43117 (diff) | |
| download | perlweeklychallenge-club-b5c46736cd45e6d03497f841e2ebb0ee69b37d62.tar.gz perlweeklychallenge-club-b5c46736cd45e6d03497f841e2ebb0ee69b37d62.tar.bz2 perlweeklychallenge-club-b5c46736cd45e6d03497f841e2ebb0ee69b37d62.zip | |
Merge pull request #4045 from dms061/master
Perl Weekly Challenge 111 submission
Diffstat (limited to 'challenge-111/dms061/python3')
| -rw-r--r-- | challenge-111/dms061/python3/ch-2-example.txt | 2 | ||||
| -rw-r--r-- | challenge-111/dms061/python3/ch-2.py | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-111/dms061/python3/ch-2-example.txt b/challenge-111/dms061/python3/ch-2-example.txt new file mode 100644 index 0000000000..2ec9193f74 --- /dev/null +++ b/challenge-111/dms061/python3/ch-2-example.txt @@ -0,0 +1,2 @@ +Longest presorted word(s) is/are 7 letters long +Word(s): ['billowy'] 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) + |
