print a ... z, A ... Z, "\n"' in Python
rzed
rzantow at gmail.com
Sat Mar 3 14:34:36 EST 2007
aleax at mac.com (Alex Martelli) wrote in
news:1hue4db.1ifwnsjmhm2pN%aleax at mac.com:
> js <ebgssth at gmail.com> wrote:
>
>> HI guys,
>>
>> How do you write Perl's
>>
>> print a ... z, A ... Z, "\n"' in Python
>>
>> In Python?
>
> This specific one is easy, though this doesn't generalize:
>
> import string
> print string.lowercase + string.uppercase
>
> For the general case, there's no way to avoid calling chr and
> ord, because a string in Python doesn't have a "natural
> successor". So the only issue is how you prefer to hide those
> calls &c (in some class or function) and you already received
> suggestions on that.
>
No ord or chr in sight:
# Inclusive character range.
def pycrange(lo,hi):
import string
chars = string.letters + " "
rstr = ''
lp = chars.find(lo)
hp = chars.find(hi)
if lp < hp:
rstr = chars[lp:hp+1]
return rstr
print pycrange('c','n')
Lame code, though.
--
rzed
More information about the Python-list
mailing list