Composition of functions

Terry Reedy tjreedy at udel.edu
Thu Jul 1 03:45:51 EDT 2010


On 7/1/2010 12:32 AM, Mladen Gogala wrote:
> On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote:

>> However, you can easily get what you want by using the 'reversed'
>> function (and similarly, the 'sorted' function), a la:
>>
>>   >>>  y = ''.join(reversed(list(x)))
>>
>> The 'reversed' and 'sorted' functions are generators that lazilly
>> convert an iterable as needed.
>
> Ah, that is even better. Thanks.

It is better if you do not mind making an unnecessary copy. If the list 
had 10 million elements, you might prefer your original. And by the way, 
sequential statements are a form of composition, even if strict 
functionalists do not like to see it that way.

-- 
Terry Jan Reedy




More information about the Python-list mailing list