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

  • SEARCH
  • Home
  • 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 8401423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:48:09+00:00 2026-06-09T21:48:09+00:00

Which of these would be considered better/clearer/faster/more ‘Pythonic’? I don’t care about the content

  • 0

Which of these would be considered better/clearer/faster/more ‘Pythonic’? I don’t care about the content of the list L, just how long it is.

a = [f(n) for n, _ in enumerate(L)]

or

a = [f(n) for n in range(len(L))]

If it makes any difference, the function f makes use of len(list) as well.

  • 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-09T21:48:11+00:00Added an answer on June 9, 2026 at 9:48 pm

    Some quick timing runs seem to give the 2nd option using range() a slight edge over enumerate():

    timeit a = [f(n) for n, _ in enumerate(mlist)]
    10000 loops, best of 3: 118 us per loop
    
    timeit a = [f(n) for n in range(len(mlist))]
    10000 loops, best of 3: 102 us per loop
    

    and just for fun using xrange() (Python v2.7.2)

    timeit a = [f(n) for n in xrange(len(mlist))]
    10000 loops, best of 3: 99 us per loop
    

    I would favor readable code first, then using xrange() if available (i.e., Pre-Python v 3.x), followed by range() and enumerate().

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

Sidebar

Related Questions

I would like to know which is considered more correct or better practice: Part
Which one of these would be more suitable for RLE on bytes? I need
Which of these queries is more efficient, and would a modern DBMS (like SQL
which library would you advise me to use? I don't know any of these
I am wondering which one of these would be considered the cleanest or best
Which amongst these would be well suited for a scalable server side TCP socket
How do you connect these to your computer? Which one would be easier to
In C++, or in general, which of the following two approaches is considered better
Are there any pre-existing solutions out there which would extend the built in SQL
I would like to write a function in which there are multiple Exit Function

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.