0% found this document useful (0 votes)
13 views

8 Python Performance Tips I Discovered After Years of Coding in Python _ by ?ode ?eass _ Oct, 2024 _ Python in Plain English

Python Performance Tips

Uploaded by

0v3ej32po
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

8 Python Performance Tips I Discovered After Years of Coding in Python _ by ?ode ?eass _ Oct, 2024 _ Python in Plain English

Python Performance Tips

Uploaded by

0v3ej32po
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

Open in app Sign up Sign in


You are signed out. Sign in with your member account
(pp__@g__.com) to view other member-only stories. Sign in
Search

Member-only story

8 Python Performance Tips I Discovered


After Years of Coding in Python
�ode �eass · Follow
Published in Python in Plain English
4 min read · Oct 11, 2024

Listen Share

Hey Everyone!! I wanted to share these Python Performance tips, that i feel that
everyone should be aware of, since it took a lot of effort and mistakes for me to
learn it. So, here are eight performance tips that have made a real difference in
my projects. Dont forget to bookmark them for further reference.

1 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

link

You are signed out. Sign in with your member account


1) Use Generators to Save
(pp__@g__.com) Memory
to view other member-only stories. Sign in
You know how sometimes you need to process a huge list of items? Like, say, a
million records from a database. Many a times, storing and retreiving all this
memory might be very resource intensive for our usecase, thats when we can use
generators that help us to generate items and hence allocate memory without the
need of loading everything at once.

Instead of:

data = [process(item) for item in big_list]

Try:

def data_generator(big_list):
for item in big_list:
yield process(item)

for item in data_generator(big_list):


# Do something with item

I remember the first time I switched to generators — it felt like magic. Suddenly,
my script wasn’t hogging all the RAM, and everything just ran smoother.

Create an account to read the full story.

The author made this story available to Medium members only.


If you’re new to Medium, create a new account to read this story on us.

Continue in app

Or, continue in mobile web

2 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

Sign up with Google


You are signed out. Sign in with your member account
(pp__@g__.com) to view other member-only stories. Sign in
Sign up with Facebook

Sign up with email

Already have an account? Sign in

Follow

Published in Python in Plain English


29K Followers · Last published 2 hours ago

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow

Written by �ode �eass


684 Followers · 56 Following

▄︻デ══━一 You can't change the world with Pretty Software alone

More from �ode �eass and Python in Plain English

3 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

You are signed out. Sign in with your member account


(pp__@g__.com) to view other member-only stories. Sign in

�ode �eass

10 Performance Tips I Discovered After Years of Coding in JAVA


Hey Everyone!! I wanted to share these Java Performance tips, that i feel everyone should be
aware of since it took a lot of effort and…

Oct 13 354 23

4 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

In Python in Plain English by Abdur Rahman

5 OverratedYouPython
are signed out. Sign in with your member account
Libraries (And What You Should Use Instead)
(pp__@g__.com) to view other member-only stories. Sign in
Traditional Devs, Look Away — This One’s Not for You!

Nov 3 1.4K 9

In Python in Plain English by Anoop Maurya

Why PyMuPDF4LLM is the Best Tool for Extracting Data from PDFs
(Even if You Didn’t Know You Needed…
Stuck behind a paywall? Read for Free!

Oct 18 1.5K 15

5 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

�ode �eass

You are signed out. Sign in with your member account


10 Awesome Developer Tools to Make Your Life Easier
(pp__@g__.com) to view other member-only stories. Sign in
Hey, so if you’re like me, constantly on the lookout for new ways to make your developer life
easier, then you’re in for a treat! I’ve put…

Sep 8 688 1

See all from �ode �eass

See all from Python in Plain English

Recommended from Medium

In Stackademic by Abdur Rahman

20 Python Scripts To Automate Your Daily Tasks


A must-have collection for every developer

Oct 6 2.4K 25

6 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

You are signed out. Sign in with your member account


(pp__@g__.com) to view other member-only stories. Sign in

In Level Up Coding by Liu Zuo Lin

12 Production-Grade Python Code Styles I’ve Picked Up From Work


Read Free…

Nov 2 1.8K 19

Lists

Coding & Development


11 stories · 893 saves

General Coding Knowledge


20 stories · 1714 saves

Predictive Modeling w/ Python


20 stories · 1649 saves

Stories to Help You Grow as a Software Developer


19 stories · 1464 saves

7 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

You are signed out. Sign in with your member account


(pp__@g__.com) to view other member-only stories. Sign in

Harendra

How I Am Using a Lifetime 100% Free Server


Get a server with 24 GB RAM + 4 CPU + 200 GB Storage + Always Free

Oct 26 3.7K 44

8 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

In Puzzle Sphere by Paolo Molignini, PhD

You are signed out. Sign in with your member account


Can you solve this famous interview question?
(pp__@g__.com) to view other member-only stories. Sign in
100 passengers, 100 seats — but the first one sits randomly! What’s the chance the last
passenger ends up in their own seat? Find out here!

Oct 5 2.2K 59

In Code Like A Girl by Nidhi Jain

7 Productivity Hacks I Stole From a Principal Software Engineer


Golden tips and tricks that can make you unstoppable

Oct 15 4.2K 80

9 of 10 11/11/2024, 7:43 AM
8 Python Performance Tips I Discovered After Years of Coding in Pyt... https://python.plainenglish.io/8-python-performance-tips-i-discovered...

In Towards Data Science by Shaw Talebi

You are signed out. Sign in with your member account


5 AI Projects You Can Build This Weekend (with Python)
(pp__@g__.com) to view other member-only stories. Sign in
From beginner-friendly to advanced

Oct 9 3.7K 59
See more recommendations

10 of 10 11/11/2024, 7:43 AM

You might also like