Re: Most elegant way to do something N times

2019-12-24 Thread Marco Sulla via Python-list
Anyway, from itertools recipes: def repeatfunc(func, times=None, *args): """Repeat calls to func with specified arguments. Example: repeatfunc(random.random) """ if times is None: return starmap(func, repeat(args)) return starmap(func, repeat(args, times)) On Tue, 24

Re: Most elegant way to do something N times

2019-12-24 Thread Marco Sulla via Python-list
On Tue, 24 Dec 2019 at 01:07, Chris Angelico wrote: > On Tue, Dec 24, 2019 at 10:45 AM Marco Sulla <...> wrote: > > ??? Excuse me, but why you needed to call the same function SIX times? This > > seems to me not elegant in primis. > > > > Can you give us a practical example? > > File parsing. You

RE: Most elegant way to do something N times

2019-12-23 Thread Avi Gross via Python-list
o a language that does not need more bloat. -----Original Message- From: Python-list On Behalf Of DL Neil via Python-list Sent: Monday, December 23, 2019 7:27 PM To: Python Subject: Re: Most elegant way to do something N times On 24/12/19 1:04 PM, Chris Angelico wrote: > On Tue, Dec 2

RE: Most elegant way to do something N times

2019-12-23 Thread Avi Gross via Python-list
r 23, 2019 6:12 PM To: Batuhan Taskaya Cc: Ian Kelly ian.g.kelly-at-gmail.com |python-list@python.org| Subject: Re: Most elegant way to do something N times > > I encounter with cases like doing a function 6 time with no argument, > or same arguments over and over or doing some stru

Re: Most elegant way to do something N times

2019-12-23 Thread Chris Angelico
On Tue, Dec 24, 2019 at 11:34 AM DL Neil via Python-list wrote: > > On 24/12/19 1:04 PM, Chris Angelico wrote: > > File parsing. You read a section header and want to ignore that > > section, so you ignore the next 15 lines. > > (just to be cheeky to @Chris) > > Perhaps better as a Finite State Ma

Re: Most elegant way to do something N times

2019-12-23 Thread DL Neil via Python-list
On 24/12/19 1:04 PM, Chris Angelico wrote: On Tue, Dec 24, 2019 at 10:45 AM Marco Sulla wrote: I encounter with cases like doing a function 6 time with no argument, or same arguments over and over or doing some structral thing N times and I dont know how elegant I can express that to the cod

Re: Most elegant way to do something N times

2019-12-23 Thread Morten W. Petersen
It depends on what's elegant, and beauty is in the eye of the beholder.. def recurse(n): print(”do be do be do”) if n>0: recurse(n-1) Regards, Morten søn. 22. des. 2019, 21:37 skrev Batuhan Taskaya : > I encounter with cases like doing a function 6 time with no argument, or > same argument

Re: Most elegant way to do something N times

2019-12-23 Thread Chris Angelico
On Tue, Dec 24, 2019 at 10:45 AM Marco Sulla wrote: > > > > > I encounter with cases like doing a function 6 time with no argument, or > > same arguments over and over or doing some structral thing N times and I > > dont know how elegant I can express that to the code. > > > > ??? Excuse me, but w

Re: Most elegant way to do something N times

2019-12-23 Thread Marco Sulla
> > I encounter with cases like doing a function 6 time with no argument, or > same arguments over and over or doing some structral thing N times and I > dont know how elegant I can express that to the code. > ??? Excuse me, but why you needed to call the same function SIX times? This seems to me

Re: Most elegant way to do something N times

2019-12-22 Thread Python
Le 22/12/2019 à 23:50, Stefan Ram a écrit : Batuhan Taskaya writes: dont like this for _ in range(n): do() thing. Any suggestions? The participants of my beginner classes like to write: n * do() for that purpose, but usuallythis does not work as intended! What would work sometimes

Re: Most elegant way to do something N times

2019-12-22 Thread Tim Chase
On 2019-12-22 23:34, Batuhan Taskaya wrote: > I encounter with cases like doing a function 6 time with no > argument, or same arguments over and over or doing some structral > thing N times and I dont know how elegant I can express that to the > code. I dont know why but I dont like this > > for _

Re: Most elegant way to do something N times

2019-12-22 Thread Mirko via Python-list
Am 22.12.2019 um 21:34 schrieb Batuhan Taskaya: > I encounter with cases like doing a function 6 time with no argument, or > same arguments over and over or doing some structral thing N times and I > dont know how elegant I can express that to the code. I dont know why but I > dont like this for _

Re: Most elegant way to do something N times

2019-12-22 Thread Richard Damon
On 12/22/19 3:34 PM, Batuhan Taskaya wrote: > I encounter with cases like doing a function 6 time with no argument, or > same arguments over and over or doing some structral thing N times and I > dont know how elegant I can express that to the code. I dont know why but I > dont like this for _ in r