[Tutor] range()-like function to generate aa, ... az, ..., zz ?
Alan G
alan.gauld at freenet.co.uk
Thu Jul 28 23:33:57 CEST 2005
Is this what you want?
>>> import string
>>> ltrs = string.lowercase
>>> [''.join([a,b]) for a in ltrs for b in ltrs]
HTH,
Alan G.
----- Original Message -----
From: "Chris Shenton" <chris at shenton.org>
To: <tutor at python.org>
Sent: Thursday, July 28, 2005 6:59 PM
Subject: [Tutor] range()-like function to generate aa, ... az, ..., zz
?
> I'm looking for a range()-like function which could generate a list
> of
> character-oriented tokens, like to iterate over all two-character
> sequences like:
>
> pseudorange('aa', 'zz') would generate:
> aa, ab, ..., az, ba, ..., za, ..., zz
>
> range() doesn't do character iteration, and I'm sure I could write
> a
> dumb function to do it, but was wondering if there was something
> more
> generic -- e.g., later I might want
>
> pseudorange('aaa', 'mmm')
>
> Anyway, is there a function to iterate through a range of character
> strings similar to this?
>
> Thanks.
>
>
More information about the Tutor
mailing list