<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Mark Tolonen:
Writing a helper function reduces code repetition and improves readability:
def crange(startch,endch):
'''Return a list of characters from startch to endch, inclusive.'''
return [chr(c) for c in xrange(ord(startch),ord(endch)+1)]

In Python ranges are open on the right, so I name cinterval such
function.

Yes, and that's fine when dealing with integers and slicing, but when dealing with characters, it is non-obvious what character to use. What "looks" correct?

  chars = crange('0','9') + crange('A','Z') + crange('a','z') # inclusive

or

  chars = crange('0',':') + crange('A','[') + crange('a','{')  # open right

or if you didn't know the character after the one you actually wanted:

chars = crange('0',chr(ord('9')+1)) + crange('A',chr(ord('Z')+1)) + crange('a',chr(ord('z')+1)) # open right, but messy

-Mark

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to