Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.048 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'exercise': 0.04; 'arguments': 0.09; 'def': 0.12; 'args.': 0.16; 'expression,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'aug': 0.22; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'anonymous': 0.31; 'extending': 0.31; 'restricted': 0.31; 'subject:that': 0.31; 'probably': 0.32; 'fri,': 0.33; "i'd": 0.34; 'received:google.com': 0.35; 'subject:?': 0.36; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'then,': 0.60; 'simply': 0.61; 'back': 0.62; '30,': 0.65; 'subject:there': 0.68; 'obvious': 0.74; 'as:': 0.81; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5rokhpCKj0kdo/pHLvhtpX3VwQTQk6uQZeE25R1AVtw=; b=i+3HkloA5laSHTnAPgv75VfrtlM9JB9ut8yWL9oBtHj/x58VPWqFMm5kNcsRM3d91Y 3vYvbShNrug0Blp3bY/CP3ocYAKaTJC4E+7lGQpFs84nXhS3OJdw04libwZ1QBmSvpCn FGsuLe56VpoPeJXXH29NiwOY3cy+tdu0pei6kJSoRQMKvzIhOknR/BmRH7W948HaxIne Bw+vJQ7gDVI8Q9BpmyRy3M6V0kabWG1KkjYaDu1f4GtxGmfqkQnRqnMjU4qPCExsGlo2 DQGt9HAagiWs0k/g9f1Q4f7LEhoAfHWyhhWpNMRrPrxFvUFe/OcKCABK99QagSE6rFx7 VqGQ== MIME-Version: 1.0 X-Received: by 10.58.201.227 with SMTP id kd3mr4873925vec.14.1377810338500; Thu, 29 Aug 2013 14:05:38 -0700 (PDT) In-Reply-To: <90afb50e-7932-4e05-a90d-7005e1de91b8@googlegroups.com> References: <90afb50e-7932-4e05-a90d-7005e1de91b8@googlegroups.com> Date: Fri, 30 Aug 2013 07:05:38 +1000 Subject: Re: Is there a function that applies list of functions to a value? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377810340 news.xs4all.nl 15919 [2001:888:2000:d::a6]:36927 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53258 On Fri, Aug 30, 2013 at 6:50 AM, wrote: > My way is so obvious that it may not be that interesting... > > def func4(f1,f2,f3,f4): > def anon(x): > f1(f2(f3(f4(x)))) > return anon Or have it return the result of f1. And then, since it's an anonymous function that simply returns an expression, I'd write it as: def func4(f1,f2,f3,f4): return lambda x: f1(f2(f3(f4(x)))) Of course, that's still restricted to precisely four args. Extending this concept to a variable number of arguments is, uhh, left as an exercise to the reader. Which will probably end up going back to reduce(). :) ChrisA