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 888325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:22:45+00:00 2026-05-15T13:22:45+00:00

I need to process lots of data in lists and so have been looking

  • 0

I need to process lots of data in lists and so have been looking at what the best way of doing this is using Python.

The main ways I’ve come up with are using:
– List comprehensions
– generator expressions
– functional style operations (map,filter etc.)

I know generally list comprehensions are probably the most “Pythonic” method, but what is best in terms of performance?

  • 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-05-15T13:22:45+00:00Added an answer on May 15, 2026 at 1:22 pm

    Inspired by this answer: Python List Comprehension Vs. Map , I’ve tweaked the questions to allow generator expressions to be compared:

    For built-ins:

    $ python -mtimeit -s 'import math;xs=range(10)' 'sum(map(math.sqrt, xs))'
    100000 loops, best of 3: 2.96 usec per loop
    $ python -mtimeit -s 'import math;xs=range(10)' 'sum([math.sqrt(x) for x in xs)]'
    100000 loops, best of 3: 3.75 usec per loop
    $ python -mtimeit -s 'import math;xs=range(10)' 'sum(math.sqrt(x) for x in xs)'
    100000 loops, best of 3: 3.71 usec per loop
    

    For lambdas:

    $ python -mtimeit -s'xs=range(10)' 'sum(map(lambda x: x+2, xs))'
    100000 loops, best of 3: 2.98 usec per loop
    $ python -mtimeit -s'xs=range(10)' 'sum([x+2 for x in xs])'
    100000 loops, best of 3: 1.66 usec per loop
    $ python -mtimeit -s'xs=range(10)' 'sum(x+2 for x in xs)'
    100000 loops, best of 3: 1.48 usec per loop
    

    Making a list:

    $ python -mtimeit -s'xs=range(10)' 'list(map(lambda x: x+2, xs))'
    100000 loops, best of 3: 3.19 usec per loop
    $ python -mtimeit -s'xs=range(10)' '[x+2 for x in xs]'
    100000 loops, best of 3: 1.21 usec per loop
    $ python -mtimeit -s'xs=range(10)' 'list(x+2 for x in xs)'
    100000 loops, best of 3: 3.36 usec per loop
    

    It appears that map is best when paired with built-in functions, otherwise, generator expressions beat out list comprehensions. Along with slightly cleaner syntax, generator expressions also save much memory over list comprehensions because they are lazily evaluated. So in the absence of specific tests for your application, you should use map with builtins, a list comprehension when you require a list result, otherwise a generator. If you’re really concerned with performance, you might take a look at whether you actually require lists at all points in your program.

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

Sidebar

Related Questions

I need to process the incoming predefined ASN format data(coming from verity of clients
I have the next problem: I need to process only 1 request at a
I am getting data from a queue server and I need to process it
Hey folks, every once in a while I have the need to automate data
I have a project where I need to generate a PDF file. Within this
I have a client that will send a lots of data to server from
I am using lucene with a tomcat application. I have lots and lots of
I have an html input field, such as <form method=post action=process.php enctype=multipart/form-data> <div> <h3>Files:</h3>
I have a very large project with lots of files. I need to extract
I have an UIScrollView with lots of tagged images. I have to process some

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.