Generate alphabet?
Emile van Sebille
emile at fenx.com
Fri Aug 22 18:17:15 EDT 2008
ssecorp wrote:
> In Haskell I can do [1..10] for range(1,11) and ['a'..'z'] for a list
> of the alphabet.
>
> Is there a way in Python to generate chars?
How about:
def haskellrange(sc,ec):
if type(sc) is int:
for ii in range(sc,ec):
yield ii
else:
for ii in range(ord(sc),ord(ec)+1):
yield chr(ii)
for jj in haskellrange(1,10): jj
for jj in haskellrange('a','z'): jj
Add salt to taste...
Emile
More information about the Python-list
mailing list