Convert from numbers to letters

Gary Wilson Jr gdub at ece.utexas.edu
Thu May 19 16:15:59 EDT 2005


Bill Mill wrote:
> On 5/19/05, Peter Otten <__peter__ at web.de> wrote:
> 
>>Bill Mill wrote:
>>
>>
>>>>Traceback (most recent call last):
>>>>File"<stdin>",line1,in?
>>>>NameError: name 'sorted' is not defined
>>>>
>>>>I think you're probably using 2.4 ??
>>>
>>>Yes, sorted() is new in python 2.4 .You could use a very lightly
>>>tested pure-python partial replacement:
>>
>>By the way, sorted() can be removed from your original post.
>>
>>Code has no effect :-)
> 
> 
> I'm gonna go ahead and disagree with you:

Me too, although I would forgo the sort altogether (while making things
a little more readable IMO):

> alpha = 'abcdefghijklmnopqrstuvwxyz'.upper()
> pairs = [''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]]
> pairs = sorted(pairs, key=len)

alpha = 'abcdefghijklmnopqrstuvwxyz'.upper()
pairs = [x for x in alpha] + [''.join((x,y)) for x in alpha for y in alpha]






More information about the Python-list mailing list