Author: iwontbecreative
Date: Sat Mar 12 02:15:58 2011
New Revision: 48848
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48848&view=rev
Log:
Use isinstance instead of type() checks. Use repr() instead of deprecated .
Also make it fully respectfull of Pep8.
Modified:
trunk/utils/codelist
Modified: trunk/utils/codelist
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/codelist?rev=48848&r1=48847&r2=48848&view=diff
==============================================================================
--- trunk/utils/codelist (original)
+++ trunk/utils/codelist Sat Mar 12 02:15:58 2011
@@ -8,35 +8,36 @@
import sys
+
def rangeify(lst):
- "Turn ranges of adjacent ints in a list into [start, end] list elements."
+ """
+ Turn ranges of adjacent ints in a list into [start, end] list elements.
+ """
lst.sort()
lst.append(None)
while True:
- for i in range(len(lst)-1):
- if type(lst[i]) == type(0) and lst[i+1] == lst[i]+1:
- lst = lst[:i] + [[lst[i], lst[i+1]]] + lst[i+2:]
+ for i in range(len(lst) - 1):
+ if isinstance(lst[i], int) and lst[i + 1] == lst[i] + 1:
+ lst = lst[:i] + [[lst[i], lst[i + 1]]] + lst[i + 2:]
break
- elif type(lst[i]) == type([]) and lst[i+1] == lst[i][-1]+1:
- lst[i][1] = lst[i+1]
- lst = lst[:i+1] + lst[i+2:]
+ elif isinstance(lst[i], list) and lst[i + 1] == lst[i][-1] + 1:
+ lst[i][1] = lst[i + 1]
+ lst = lst[:i + 1] + lst[i + 2:]
break
else:
break
lst.pop()
return lst
+
def printbyrange(lst):
out = ""
for elt in lst:
- if type(elt) == type(0):
- out += `elt` + ","
+ if isinstance(elt, int):
+ out += repr(elt) + ","
else:
out += "%d-%d," % tuple(elt)
return out[:-1]
codepoints = map(lambda x: int(x.strip()), sys.stdin.readlines())
print printbyrange(rangeify(codepoints))
-
-
-
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits