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

  • @patloeber
    @patloeber2 жыл бұрын

    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

  • @learnwithraghuIT
    @learnwithraghuIT2 жыл бұрын

    Dam, That's good. Look forward for more such videos

  • @name1355_0ne
    @name1355_0ne2 жыл бұрын

    Thanks for the video, it was useful

  • @krystianprogress4521
    @krystianprogress45212 жыл бұрын

    Thank you for this tips :)

  • @fullstackspiderman
    @fullstackspiderman2 жыл бұрын

    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.

  • @fuckooo
    @fuckooo2 жыл бұрын

    Thank you, some great tips here

  • @patloeber

    @patloeber

    2 жыл бұрын

    Glad it was helpful!

  • @ninjanape
    @ninjanape2 жыл бұрын

    Thanks!

  • @saurrav3801
    @saurrav38012 жыл бұрын

    Nice video bro..🔥🔥🤙

  • @tigrayrimey6418
    @tigrayrimey64182 жыл бұрын

    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

  • @manishcodeshala9639
    @manishcodeshala96392 жыл бұрын

    great video

  • @inLofiLife
    @inLofiLife Жыл бұрын

    "We should be always searching for opportunities to remove duplicated code" - now I know you're like me :) thanks for the tips!

  • @bosadam3516
    @bosadam35162 жыл бұрын

    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!

  • @wilsvenleong96
    @wilsvenleong962 жыл бұрын

    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

  • @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 (:

  • @ulissesalvesoffsec
    @ulissesalvesoffsec2 жыл бұрын

    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"

  • @_demonamv
    @_demonamv2 жыл бұрын

    Which VS code theme don you use??

  • @donnakillian1457
    @donnakillian14572 жыл бұрын

    Fascinating 😝😝😝 💖🔆🤪

  • @Mdroudian
    @Mdroudian2 жыл бұрын

    tabnine + sourcery = excellence =D

  • @user-dm3qn7wv6v
    @user-dm3qn7wv6v2 жыл бұрын

    Tip 7. When checking if character is in string, should I convert a string into set?

  • @MrDgf97

    @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

    @user-dm3qn7wv6v

    2 жыл бұрын

    @@MrDgf97 thanks!

  • @sangchoo1201
    @sangchoo12012 жыл бұрын

    where's tip no.0? index not starting with 0?

  • @MrEo89
    @MrEo892 жыл бұрын

    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?

  • @toboletsgo6103
    @toboletsgo61032 жыл бұрын

    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
    @higheloguy90572 жыл бұрын

    Tip number 1 xD? For those people that cant tie their shoes.

  • @patloeber

    @patloeber

    2 жыл бұрын

    Gotta start with a simple one 😂

  • @__________________________6910
    @__________________________69102 жыл бұрын

    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

  • @natnaelkahsu8708
    @natnaelkahsu87082 жыл бұрын

    can you make subtitles in german.

  • @Batman099
    @Batman0992 жыл бұрын

    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...