diff options
| author | Abigail <abigail@abigail.be> | 2021-05-04 12:04:46 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-05-04 12:04:46 +0200 |
| commit | e674b457aa9a8912365f1ac52a1eaf4e3d386ddc (patch) | |
| tree | d9dc342dc3d599559b0c4fa28db2355c6e44caff | |
| parent | 01863a959124994447b60f267c0e6c516f3380d1 (diff) | |
| download | perlweeklychallenge-club-e674b457aa9a8912365f1ac52a1eaf4e3d386ddc.tar.gz perlweeklychallenge-club-e674b457aa9a8912365f1ac52a1eaf4e3d386ddc.tar.bz2 perlweeklychallenge-club-e674b457aa9a8912365f1ac52a1eaf4e3d386ddc.zip | |
Python solution for week 111, part 2
| -rw-r--r-- | challenge-111/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-111/abigail/python/ch-2.py | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md index 1b8e0cd4dd..eb38f91e14 100644 --- a/challenge-111/abigail/README.md +++ b/challenge-111/abigail/README.md @@ -56,6 +56,7 @@ to standard output. In case of ties, we print the first one found. * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) +* [Python](python/ch-2.py) ### Blog diff --git a/challenge-111/abigail/python/ch-2.py b/challenge-111/abigail/python/ch-2.py new file mode 100644 index 0000000000..ce79d6b393 --- /dev/null +++ b/challenge-111/abigail/python/ch-2.py @@ -0,0 +1,35 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput +import string +import re + + +# +# Create a pattern which matches words with their characters in lexical order. +# +pat = "^" +for x in list (string . ascii_lowercase): + pat = pat + x + "*" +pat += "$" + + +# +# Match strings with their characters in lexical order, and remember +# the longest of them. +# +longest = "" +for line in fileinput . input (): + line = line . strip () + if re . match (pat, line . lower ()) and len (line) > len (longest): + longest = line + +print (longest) |
