On 5/19/05, Peter Otten <[EMAIL PROTECTED]> 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: >>> sorted([''.join((x, y)) for x in alpha \ ... for y in [''] + [z for z in alpha]], key=len) == \ ... [''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]] False If you want to see why, here's a small example: >>> alpha = 'abc' >>> [''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]] ['a', 'aa', 'ab', 'ac', 'b', 'ba', 'bb', 'bc', 'c', 'ca', 'cb', 'cc'] >>> sorted([''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]], key=len) ['a', 'b', 'c', 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'] Peace Bill Mill bill.mill at gmail.com -- http://mail.python.org/mailman/listinfo/python-list