Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66921 > unrolled thread

Functions help

Started byScott W Dunning <swdunning@cox.net>
First post2014-02-22 22:43 -0700
Last post2014-02-24 02:32 -0800
Articles 2 on this page of 22 — 14 participants

Back to article view | Back to comp.lang.python


Contents

  Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-22 22:43 -0700
    Re: Functions help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 08:44 +0000
    Re: Functions help alex23 <wuwei23@gmail.com> - 2014-02-24 10:55 +1000
      Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 01:09 +0000
        Re: Functions help alex23 <wuwei23@gmail.com> - 2014-02-24 11:39 +1000
          Re: Functions help Benjamin Kaplan <benjamin.kaplan@case.edu> - 2014-02-23 18:55 -0800
            Re: Functions help Grant Edwards <invalid@invalid.invalid> - 2014-02-24 15:38 +0000
          Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 03:21 +0000
            Re: Functions help rurpy@yahoo.com - 2014-02-23 20:01 -0800
              Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 13:59 +0000
              Re: Functions help Ethan Furman <ethan@stoneleaf.us> - 2014-02-25 18:52 -0800
                Re: Functions help rurpy@yahoo.com - 2014-02-26 17:06 -0800
          Re: Functions help MRAB <python@mrabarnett.plus.com> - 2014-02-24 03:36 +0000
        Re: Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-23 18:43 -0700
        Re: Functions help Roy Smith <roy@panix.com> - 2014-02-23 20:28 -0500
      Re: Functions help Travis Griggs <travisgriggs@gmail.com> - 2014-02-23 17:27 -0800
    Re: Functions help "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-24 01:01 +0000
      Re: Functions help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-24 21:18 -0500
        Re: Functions help "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-27 22:49 +0000
    Re: Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-23 18:24 -0700
    Re: Functions help sffjunkie@gmail.com - 2014-02-24 02:15 -0800
    Re: Functions help sffjunkie@gmail.com - 2014-02-24 02:32 -0800

Page 2 of 2 — ← Prev page 1 [2]


#66974

Fromsffjunkie@gmail.com
Date2014-02-24 02:15 -0800
Message-ID<3b84db4a-a8d5-48d9-9ead-da1f238c4ee8@googlegroups.com>
In reply to#66921
On Sunday, 23 February 2014 05:43:17 UTC, Scott W Dunning  wrote:
> I had a question regarding functions.  Is there a way to call a function multiple times without recalling it over and over.  Meaning is there a way I can call a function and then add *5 or something like that?
> 

The following answers your question but is probably not a method you want to employ.

from functools import partial

def a(ch):
  print(ch)

def b(x):
  print(x + 10)

[x() for x in [partial(a, 'd'), partial(b, 10)]*5]

Produces

d
14
d
14
d
14
d
14
d
14

--Simon

[toc] | [prev] | [next] | [standalone]


#66975

Fromsffjunkie@gmail.com
Date2014-02-24 02:32 -0800
Message-ID<1e5c02e3-010a-4eec-b0b4-b147492fb9fe@googlegroups.com>
In reply to#66921
On Sunday, 23 February 2014 05:43:17 UTC, Scott W Dunning  wrote:
 
> I had a question regarding functions.  Is there a way to call a function multiple times without recalling it over and over.  Meaning is there a way I can call a function and then add *5 or something like that?

The following answers your question but is probably not a method you want to employ. 

from functools import partial 

def a(ch): 
  print(ch) 

def b(x): 
  print(x + 4) 

[x() for x in [partial(a, 'd'), partial(b, 10)]*5] 

Produces 

d 
14 
d 
14 
d 
14 
d 
14 
d 
14 

--Simon 

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web