Super Quick Python Refactoring Tips

  Рет қаралды 41,958

Patrick Loeber

Patrick Loeber

2 жыл бұрын

In this Python Tutorial I show you another 8 quick Python refactoring tips for cleaner and more Pythonic code. This is part 2 of my refactoring code series.
✅ Sourcery - Free VS Code & PyCharm Extension for Refactoring: sourcery.ai/?... *
Refactoring video part 1: • Quick Python Refactori...
Get my Free NumPy Handbook:
www.python-engineer.com/numpy...
⭐ Join Our Discord : / discord
📓 ML Notebooks available on Patreon:
/ patrickloeber
If you enjoyed this video, please subscribe to the channel:
▶️ : / @patloeber
Resources: sourcery.ai/blog/explaining-r...
~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
🖥️ Website: www.python-engineer.com
🐦 Twitter - / patloeber
✉️ Newsletter - www.python-engineer.com/newsl...
📸 Instagram - / patloeber
🦾 Discord: / discord
▶️ Subscribe: / @patloeber
~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
🅿 Patreon - / patrickloeber
#Python
----------------------------------------------------------------------------------------------------------
* This is an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏

Пікірлер: 46
@patloeber
@patloeber 2 жыл бұрын
Small correction: In Tip 7 it should be - if currency in {"USD", "EUR"} - to use a set. So it must be curly braces and not parenthesis. Hope you enjoyed the video!
@Sabre00
@Sabre00 2 жыл бұрын
I use this all the time with a List. Will change it to a Set moving forward. Excellent video as always!
@BartDorlandt
@BartDorlandt 2 жыл бұрын
Isn't a tuple for effective for this. A set would only be useful when you want to enforce uniqueness. In this case a tuple is perfect.
@NoProblem76
@NoProblem76 2 жыл бұрын
I wonder what’s the performance difference in such a small collection between list set and tuple
@dariuszspiewak5624
@dariuszspiewak5624 Жыл бұрын
In all earnest... There's no difference whether you use a list, a set,or a tuple here. There are just not enough elements to feel any difference. It'll start to show only when the number of elements goes into, say, hundreds or thousands.
@olivermohr417
@olivermohr417 Жыл бұрын
you can also predefine standard_currencies = {"USD", "EUR"} outside the function to avoid the creation of the set each time the function is called
@fullstackspiderman
@fullstackspiderman 2 жыл бұрын
4:00: values are in a tuple/() not in a set/{}. Did you mean tuple or set actually?
@qwertical
@qwertical Жыл бұрын
You must have gotten the answer already, but I am just putting it here for the comments. It should be a set like he said, not a tuple like was shown.
@name1355_0ne
@name1355_0ne 2 жыл бұрын
Thanks for the video, it was useful
@learnwithraghuIT
@learnwithraghuIT 2 жыл бұрын
Dam, That's good. Look forward for more such videos
@krystianprogress4521
@krystianprogress4521 2 жыл бұрын
Thank you for this tips :)
@fuckooo
@fuckooo 2 жыл бұрын
Thank you, some great tips here
@patloeber
@patloeber 2 жыл бұрын
Glad it was helpful!
@ninjanape
@ninjanape 2 жыл бұрын
Thanks!
@wilsvenleong96
@wilsvenleong96 2 жыл бұрын
4:00 Isn't a set in Python initialized with curly braces?
@patloeber
@patloeber 2 жыл бұрын
Totally right, thanks for letting me know! I pinned a comment with the correction
@inLofiLife
@inLofiLife Жыл бұрын
"We should be always searching for opportunities to remove duplicated code" - now I know you're like me :) thanks for the tips!
@tigrayrimey6418
@tigrayrimey6418 2 жыл бұрын
Nice tips, thanks. could you please do some python code implementation for the Passive-aggressive algorithm for the multiclass classification case?
@patloeber
@patloeber 2 жыл бұрын
thanks! Will have a look at that
@saurrav3801
@saurrav3801 2 жыл бұрын
Nice video bro..🔥🔥🤙
@shaishai416
@shaishai416 Жыл бұрын
amazing video...! please do more videos like that with refactore code, "code smell" I learn a a lot from that. and BTW the AI tool is nice... I you know more like this please let us know (:
@manishcodeshala9639
@manishcodeshala9639 2 жыл бұрын
great video
@bosadam3516
@bosadam3516 2 жыл бұрын
Hi. Nice tricks I was trying 03:52 before I watch it :D currencies = ["USD", "EUR"] def process_payment(payment, currency): if currency in currencies: print(f"Payment: {payment} and currency is: {currency}") else: print(f"Global: {payment}") Thanks ^_^
@patloeber
@patloeber 2 жыл бұрын
nice!
@ulissesalvesoffsec
@ulissesalvesoffsec 2 жыл бұрын
For tip #7, I would do like this so I don't need if's: payment_types = {"USD": process_standard_payment, "EUR": process_international_payment} def process_payment(payment, currency): payment_types[currency](payment)
@sangchoo1201
@sangchoo1201 2 жыл бұрын
that's not the same code. video's code was "run standard_payment if currency is "CSD" or "EUR", otherwise run international one" but your code is "run different payment depend on the currency"
@donnakillian1457
@donnakillian1457 2 жыл бұрын
Fascinating 😝😝😝 💖🔆🤪
@_demonamv
@_demonamv 2 жыл бұрын
Which VS code theme don you use??
@Mdroudian
@Mdroudian 2 жыл бұрын
tabnine + sourcery = excellence =D
@user-dm3qn7wv6v
@user-dm3qn7wv6v Жыл бұрын
Tip 7. When checking if character is in string, should I convert a string into set?
@MrDgf97
@MrDgf97 Жыл бұрын
Unless you’re checking a lot of characters, there’s no point. Turning a string into a set takes the same amount of time as just checking if a character exists in a string.
@user-dm3qn7wv6v
@user-dm3qn7wv6v Жыл бұрын
@@MrDgf97 thanks!
@MrEo89
@MrEo89 2 жыл бұрын
Except “is_winning” is undefined.. so assuming most people would try these in repl and find them not to work, why not come out with better example?
@sangchoo1201
@sangchoo1201 2 жыл бұрын
where's tip no.0? index not starting with 0?
@toboletsgo6103
@toboletsgo6103 2 жыл бұрын
4:02 you show tuple instead of set.
@patloeber
@patloeber 2 жыл бұрын
Yeah noticed this after the video :( thanks for the hint, I already pinned a comment
@higheloguy9057
@higheloguy9057 2 жыл бұрын
Tip number 1 xD? For those people that cant tie their shoes.
@patloeber
@patloeber 2 жыл бұрын
Gotta start with a simple one 😂
@natnaelkahsu8708
@natnaelkahsu8708 2 жыл бұрын
can you make subtitles in german.
@__________________________6910
@__________________________6910 2 жыл бұрын
I know this except 5 and 8 points.
@patloeber
@patloeber 2 жыл бұрын
Great! At least you learned 2 new things :)
@__________________________6910
@__________________________6910 2 жыл бұрын
@@patloeber humm Thanks
@Batman099
@Batman099 2 жыл бұрын
tip number 1 is not even tip. 🧐 that's how people declared list.
@patloeber
@patloeber 2 жыл бұрын
had to start with an easy one :D but sometimes you still find this in other people's code...
10 Python Basics You Should Know!
10:08
Patrick Loeber
Рет қаралды 78 М.
Knowing this can save you HOURS of debugging! (5 Python Pitfalls)
10:45
2000000❤️⚽️#shorts #thankyou
00:20
あしざるFC
Рет қаралды 16 МЛН
1❤️#thankyou #shorts
00:21
あみか部
Рет қаралды 88 МЛН
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 86 МЛН
Hot Ball ASMR #asmr #asmrsounds #satisfying #relaxing #satisfyingvideo
00:19
Oddly Satisfying
Рет қаралды 49 МЛН
6 Tips to write BETTER For Loops in Python
9:19
Patrick Loeber
Рет қаралды 246 М.
31 ESSENTIAL Python String Methods
11:20
Patrick Loeber
Рет қаралды 81 М.
7 Python Code Smells: Olfactory Offenses To Avoid At All Costs
22:10
11 Tips And Tricks To Write Better Python Code
11:00
Patrick Loeber
Рет қаралды 602 М.
If You’re Not Using Python DATA CLASSES Yet, You Should 🚀
10:55
CODE ROAST: Yahtzee - New Python Code Refactoring Series!
45:58
ArjanCodes
Рет қаралды 67 М.
Quick Python Refactoring Tips
5:07
Patrick Loeber
Рет қаралды 109 М.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 293 М.
2000000❤️⚽️#shorts #thankyou
00:20
あしざるFC
Рет қаралды 16 МЛН