Range of characters?

David Brady daves_spam_dodging_account at yahoo.com
Wed Dec 26 11:14:58 EST 2001


Hello,

I want to iterate over a range of characters, and
though I have a solution, it "feels wrong"... I think
(I hope, anyway) that I'm getting along well enough
with Python that I can tell when I've strayed from the
Pythonic Way.  What's the best way to do this?

Suppose, for example, that we want to generate every
possible name for Python and it's clones, Aython,
Bython, Cython, etc.  Here is the code I would write
to do it:

for c in range(ord('A'), ord('Z')+1):
    print "%sython" % chr(c)

It seems to me that flipping back and forth between
ord and chr, and especially the ord('Z')+1 have a
hackish smell to them.  Is there a better way?

Thank you,

-dB

=====
David Brady
daves_spam_dodging_account at yahoo.com
I'm feeling very surreal today... or *AM* I?

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com




More information about the Python-list mailing list