Skip to content

Commit b7878d0

Browse files
committed
Modernize the code a bit:
use re module use .split() string method Doesn't use 'for line in sys.stdin'; that ends up changing its interactive behaviour.
1 parent 946c53e commit b7878d0

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Demo/comparisons/sortingtest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
# - Outputs the sorted fields with exactly one space between them
2424
# - Handles blank input lines correctly
2525

26-
import regex
26+
import re
2727
import string
2828
import sys
2929

3030
def main():
31-
prog = regex.compile('^\(.*\)=\([-+]?[0-9]+\)')
31+
prog = re.compile('^(.*)=([-+]?[0-9]+)')
3232
def makekey(item, prog=prog):
33-
if prog.match(item) >= 0:
34-
var, num = prog.group(1, 2)
33+
match = prog.match(item)
34+
if match:
35+
var, num = match.group(1, 2)
3536
return string.atoi(num), var
3637
else:
3738
# Bad input -- pretend it's a var with value 0
@@ -40,7 +41,7 @@ def makekey(item, prog=prog):
4041
line = sys.stdin.readline()
4142
if not line:
4243
break
43-
items = string.split(line)
44+
items = line.split()
4445
items = map(makekey, items)
4546
items.sort()
4647
for num, var in items:

0 commit comments

Comments
 (0)