blob: ce79d6b3936716b62b5c0beaed3b329f53271249 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
|