Most elegant way to generate 3-char sequence
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Jun 12 21:40:52 EDT 2006
James Stroud a écrit :
> SuperHik wrote:
>
>> and the winner is... :D
>> David Isaac wrote:
>>
>>> alpha = string.lowercase
>>> x=(a+b+c for a in alpha for b in alpha for c in alpha)
>>
>>
>>
>>
>
> Not necessarily vying for winner, but David's solution is highly
> specific as it doesn't do so well for something like
>
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
> .
> .
> .
> zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy
> zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
>
And ? Was it asked for ?
I'd personaly start with David's solution - IOW : simplest thing that
could possibly work -, and only bother making it more generic if/when I
have a use case for a more generic solution.
Premature generalisation is the root of all evil !-)
More information about the Python-list
mailing list