On May 8, 12:24 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > <[EMAIL PROTECTED]> wrote: > > ... > > > def p(a,b): > > if list( a ) != sorted( list( a ) ): raise ValueError, "String not > > ordered." > > if not b: return [''] > > return [i+j for i in list(a) for j in p(a,b-1)] > > No need for 2/3 of the list(...) calls. sorted(a) and sorted(list(a)) > will ALWAYS be the same sequence; "for i in a" and "for i in list(a)" > will always iterate on the same sequence [as long as you're not changing > a inside the iteration, which, in this case, you aren't]. > > Alex
Ah quite true. list( a ) != sorted( a ). ...for i in a for... -- http://mail.python.org/mailman/listinfo/python-list