11 Tips and Tricks for Writing Better Python Code

11 Tips and Tricks for Writing Better Python Code

HomePatrick Loeber11 Tips and Tricks for Writing Better Python Code
11 Tips and Tricks for Writing Better Python Code
ChannelPublish DateThumbnail & View CountDownload Video
Channel AvatarPublish Date not found Thumbnail
0 Views
In this video I show 11 tips and tricks for writing better Python code! I show many best practices that improve your code making it much cleaner and more Pythonic.

Find Python Jobs: https://pythonengineer.pallet.com

GREAT PLUGINS FOR YOUR CODE EDITOR
Write cleaner code with Sourcery: https://sourcery.ai/?utm_sourceyoutube&utm_campaignpythonengineer *

Get my FREE NumPy manual:
https://www.python-engineer.com/numpybook

Notebooks available on Patreon:
https://www.patreon.com/patrickloeber

Join our Discord: https://discord.gg/FHMg9tKFSN

If you enjoyed this video, subscribe to the channel!

All the advice:
1) Iterate with enumerate instead or range(len(x))
2) Use list comprehension instead of raw for loops
3) Sort complex iterables with sorted()
4) Store unique values with sets
5) Save memory with generators
6) Set default values in dictionaries with .get() and .setdefault()
7) Count hashable objects with collections.Counter
8) Format strings with f-Strings (Python 3.6)
9) Concatenate strings with .join()
10) Merge dictionaries with {**d1, **d2} (Python 3.5)
11) Simplify if statements with if x in the list

List comprehension tutorial: https://youtu.be/RaIu2-NM0t0

CONNECT

️ Website: https://www.python-engineer.com
Twitter – https://twitter.com/patloeber
️ Newsletter – https://www.python-engineer.com/newsletter
Instagram – https://www.instagram.com/patloeber
Discord: https://discord.gg/FHMg9tKFSN
️ Subscribe: https://www.youtube.com/channel/UCbXgNpp0jedKWcQiULLbDTA?sub_confirmation1

TO SUPPORT ME

Patreon – https://www.patreon.com/patrickloeber

Music: https://www.bensound.com/

#Python #Tips

————————————————– ————————————————– ——
*This is a sponsored or affiliate link. By clicking on it, you will not incur any additional costs, but you will be supporting me and my project. Thank you very much for your support!

Please take the opportunity to connect and share this video with your friends and family if you find it useful.