Super Quick Python Refactoring Tips
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
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
2 жыл бұрын
I use this all the time with a List. Will change it to a Set moving forward. Excellent video as always!
@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
2 жыл бұрын
I wonder what’s the performance difference in such a small collection between list set and tuple
@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
Жыл бұрын
you can also predefine standard_currencies = {"USD", "EUR"} outside the function to avoid the creation of the set each time the function is called
Dam, That's good. Look forward for more such videos
Thanks for the video, it was useful
Thank you for this tips :)
4:00: values are in a tuple/() not in a set/{}. Did you mean tuple or set actually?
@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.
Thank you, some great tips here
@patloeber
2 жыл бұрын
Glad it was helpful!
Thanks!
Nice video bro..🔥🔥🤙
Nice tips, thanks. could you please do some python code implementation for the Passive-aggressive algorithm for the multiclass classification case?
@patloeber
2 жыл бұрын
thanks! Will have a look at that
great video
"We should be always searching for opportunities to remove duplicated code" - now I know you're like me :) thanks for the tips!
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
2 жыл бұрын
nice!
4:00 Isn't a set in Python initialized with curly braces?
@patloeber
2 жыл бұрын
Totally right, thanks for letting me know! I pinned a comment with the correction
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 (:
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
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"
Which VS code theme don you use??
Fascinating 😝😝😝 💖🔆🤪
tabnine + sourcery = excellence =D
Tip 7. When checking if character is in string, should I convert a string into set?
@MrDgf97
2 жыл бұрын
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
2 жыл бұрын
@@MrDgf97 thanks!
where's tip no.0? index not starting with 0?
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?
4:02 you show tuple instead of set.
@patloeber
2 жыл бұрын
Yeah noticed this after the video :( thanks for the hint, I already pinned a comment
Tip number 1 xD? For those people that cant tie their shoes.
@patloeber
2 жыл бұрын
Gotta start with a simple one 😂
I know this except 5 and 8 points.
@patloeber
2 жыл бұрын
Great! At least you learned 2 new things :)
@__________________________6910
2 жыл бұрын
@@patloeber humm Thanks
can you make subtitles in german.
tip number 1 is not even tip. 🧐 that's how people declared list.
@patloeber
2 жыл бұрын
had to start with an easy one :D but sometimes you still find this in other people's code...