diff options
| author | Andrew M. Kuchling <amk@amk.ca> | 2003-04-24 17:13:18 (GMT) |
|---|---|---|
| committer | Andrew M. Kuchling <amk@amk.ca> | 2003-04-24 17:13:18 (GMT) |
| commit | 946c53ed7ff53f38792ac35e5da21de3e0a48ef2 (patch) | |
| tree | f4e9d42bd70a153c2b1f5d2394d123a15ccf6c98 /Demo/comparisons/sortingtest.py | |
| parent | 4f237b6870bc856e2af5f23e524a9d32cd42e027 (diff) | |
| download | cpython-946c53ed7ff53f38792ac35e5da21de3e0a48ef2.zip cpython-946c53ed7ff53f38792ac35e5da21de3e0a48ef2.tar.gz cpython-946c53ed7ff53f38792ac35e5da21de3e0a48ef2.tar.bz2 | |
Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Diffstat (limited to 'Demo/comparisons/sortingtest.py')
| -rwxr-xr-x | Demo/comparisons/sortingtest.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/Demo/comparisons/sortingtest.py b/Demo/comparisons/sortingtest.py index d6c213c..8fe2bbb 100755 --- a/Demo/comparisons/sortingtest.py +++ b/Demo/comparisons/sortingtest.py @@ -1,17 +1,17 @@ #! /usr/bin/env python # 2) Sorting Test -# +# # Sort an input file that consists of lines like this -# +# # var1=23 other=14 ditto=23 fred=2 -# +# # such that each output line is sorted WRT to the number. Order # of output lines does not change. Resolve collisions using the # variable name. e.g. -# -# fred=2 other=14 ditto=23 var1=23 -# +# +# fred=2 other=14 ditto=23 var1=23 +# # Lines may be up to several kilobytes in length and contain # zillions of variables. @@ -28,23 +28,23 @@ import string import sys def main(): - prog = regex.compile('^\(.*\)=\([-+]?[0-9]+\)') - def makekey(item, prog=prog): - if prog.match(item) >= 0: - var, num = prog.group(1, 2) - return string.atoi(num), var - else: - # Bad input -- pretend it's a var with value 0 - return 0, item - while 1: - line = sys.stdin.readline() - if not line: - break - items = string.split(line) - items = map(makekey, items) - items.sort() - for num, var in items: - print "%s=%s" % (var, num), - print + prog = regex.compile('^\(.*\)=\([-+]?[0-9]+\)') + def makekey(item, prog=prog): + if prog.match(item) >= 0: + var, num = prog.group(1, 2) + return string.atoi(num), var + else: + # Bad input -- pretend it's a var with value 0 + return 0, item + while 1: + line = sys.stdin.readline() + if not line: + break + items = string.split(line) + items = map(makekey, items) + items.sort() + for num, var in items: + print "%s=%s" % (var, num), + print main() |
