Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:17:07+00:00 2026-06-01T11:17:07+00:00

Consider the hypothetical function repeatcall , that takes as arguments a no-args callable func

  • 0

Consider the hypothetical function repeatcall, that takes as arguments a no-args callable func and a positive integer n, and returns a list whose members are obtained by executing func() n times. It supports an infinite stream of silly hijinks like:

>>> repeatcall(lambda: id(dict()), 5)
[45789920, 45788064, 45807216, 45634816, 45798640]

>>> urandom = lambda: struct.unpack('Q', open('/dev/urandom').read(8))[0]
>>> repeatcall(urandom, 3)
[3199039843823449742, 14990726001693341311L, 11583468019313082272L]

>>> class Counter(itertools.count): __call__ = itertools.count.next
>>> repeatcall(Counter(100, -2), 4)
[100, 98, 96, 94]

I could swear that I’ve seen a function like repeatcall somewhere in the Python 2.x standard libraries, but I can’t find it. If I didn’t dream this, where in the standard library can I find it?

PS: I know it’s trivial to roll one’s own, but I hate to reinvent wheels, especially those are already in the standard library. I am not asking how to roll my own.

Edit: made it even more explicit that I am not asking how to code repeatcall.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:17:08+00:00Added an answer on June 1, 2026 at 11:17 am

    You’ve seen this in the standard library docs, not the standard library itself.

    It’s repeatfunc from the 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))
    

    It allows arguments and should (theoretically) perform better than a list comprehension because func only has to be looked up once. repeat is also faster than range for when you’re not actually using the counter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a hypothetical method of an object that does stuff for you: public class
This question requires some hypothetical background. Let's consider an employee table that has columns
Consider that I've a excel sheet in below format: person age Foo 29 Bar
Consider this scenario. I have my own website, that I use as my identifier,
Consider the following hypothetical people management system. Suppose each Person object belong to a
Consider the following two (hypothetical) tables Temperature * day * time * lake_name *
This is kind of hypothetical as I'm thinking about how to design this. Consider
(This is a hypothetical question for discussion, I have no actual problem). Say that
Consider these two functions: 'Overload 1 <Extension()> Function ComputeReturnValue(Of TSource, TResult)(ByVal source As TSource,
Consider the following SML function: fn x => x x This produces the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.