I hope you find these tips helpful! Let me know if you have any other Python tips that improve your code :)
@uploadvoice4 жыл бұрын
Helpful but too many ads cut...
@kingkhann93 жыл бұрын
Can you iterate from say idx 2 to n-4 of a list using enumerate without slicing or any extra lines of code...
@abhisheksanwal11063 жыл бұрын
@@sudhanshuranjan9 ya membership test is faster in set
@Princess0Reem3 жыл бұрын
remarkable!
@jorgemercadog3 жыл бұрын
Thank you!! Cheers from Chile!
@IlyaLisovfan3 жыл бұрын
In Python 3.9.0 or greater we can merge dictionaries using `|`: d1 = {"name": "Alex", "age": 25} d2 = {"name": "Alex", "city": "New York"} merged_dict = d1 | d2
@drygordspellweaver87612 жыл бұрын
I like this as it stays true to Pipe symbol
@billw8dsx9392 жыл бұрын
you rock
@DailyDoseOfCCP2 жыл бұрын
And print(merged_dict == d1 | d2) will print out true
@flames93102 жыл бұрын
This syntax is way simpler.
@albo51942 жыл бұрын
Is there an easy (and fast for large dictionaries) way to merge dictionaries in a way, that it includes every value of both dicts with the same key? for example, if d2 would include "name": "Luca" instead of "Alex", i would like the merged output to be like: {"name": ["Alex", "Luca"], "age": 25, "city": "New York"}
@FailedSquare4 жыл бұрын
0:20 Iterate with Enumerate x For Loops with If 1:02 List Comprehension x For Loops 1:51 Sort iterables with sorted() 3:00 Unique values with Sets 3:37 Generators replacement for Lists 4:58 default values for dictionary keys 6:06 Count objects with collections.Counter 7:39 f-Strings > str.format() 8:20 Build up strings with .join() 9:27 merge dictionaries - This feature is updated again in 3.9 using | 10:00 simplify if statements
@patloeber4 жыл бұрын
Thanks for the summary :)
@yt-sh3 жыл бұрын
@@patloeber you made this in 11 min, I see what u did there
@DavidTangye3 жыл бұрын
@@patloeber This is a very nice video for quick reference on these coding best practices. Can you please copy this list of times to the video Description for future reference. That makes the vid hugely helpful for in future.
@Daniel-um9ye2 жыл бұрын
Superb content. I am a C++ programmer, but since 2019 have been dabbling with python. Being pythonic is actually what I look for as of now. Thanks.
@evanhagen70843 жыл бұрын
On the last tip it would be much faster to use a set instead of a list. Sets have constant lookup time but lists have O(n) lookup time.
@sshishov3 жыл бұрын
To convert list into set you need to execute O(n) operation.
@evanhagen70843 жыл бұрын
@@sshishov my point is you shouldn't even create a list in the first place. You should create a set to begin with
@sshishov3 жыл бұрын
Agree, but sometimes lists are needed if you want to keep duplicates or you want to keep items in inserted order.
@andraspongracz59963 жыл бұрын
@@sshishov True, but if you want to check membership, say, n times, than its O(n) vs. O(n**2). It depends on the problem which data structure is better, as your second comment shows. But if you are only worried about runtime, then @Evan Hagen is correct: you basically cannot lose by using a set (I mean even if you have to convert first), because if you run it once, it is the same runtime, but if you do it many times, then set is the better choice.
@sshishov3 жыл бұрын
@@andraspongracz5996 agree 👍
@etgaming6063 Жыл бұрын
If you aren't speeding up your videos during your scripting then you are a REALLY FAST typer, like holy crap. IDK how you can type those lists in under a second, that is crazy to me.
@jth57262 жыл бұрын
dude, I've been doing a programming course 12 weeks, I feel like f-strings are something we should have been taught immediately, why am I only learning it through you
@eminm63832 жыл бұрын
I almost don't know any python, but I was able to comprehend 80% of the content. Amazing simple explanation. Thanks.
@manuelmanolo70992 жыл бұрын
I thought this would be something that would go way over my head but, as some that recently started learning python, this was really valuable!
@jordangl12 жыл бұрын
Your videos are by far the most concise and easiest to assimilate compared to every other YT Python teacher (to me). Thanks for taking the time. Good stuff
@schedarr3 жыл бұрын
That is absolutely golden video. Extremaly useful tricks that will make your life way much easier. I've already used 10 out of 11 but still it's nice refresher.
@patloeber3 жыл бұрын
Great to hear!
@stevenwilson55563 жыл бұрын
The Squares example.. here's Python code: squares = [i*i for i in range(15)] print(squares) Here's the R code: x = 1:14; x^2 Python 48 characters, 2 lines R 13 characters, 1 line Advantage: R.
@stevenwilson55563 жыл бұрын
at 4:15 using generators: Python: my_gen = (i for i in range(10000)) print(sum(my_gen)) R: x = 1:1e4; sum(x) Python 52 R 17 Advantage: R.
@saurabhjain5074 жыл бұрын
I love how you explain with simplicity. Great content.
@patloeber4 жыл бұрын
Thank you! Glad you like it!
@Arson_Oakwood9 ай бұрын
I'm amazed at how there are beginner programmers, who never read basic tutorial in official documentation, and then watch similar videos, thinking they are learning advanced concepts.
@RicardoAmaralAndrade3 жыл бұрын
Simply wonderful! Subscribed in the first 2 minutes! Python is the greatest modern language, and these tips are gold!
@patloeber3 жыл бұрын
Thank you so much!
@YouAreNotFree13 жыл бұрын
First example: return [max(i, 0) for i in data]
@vitalimueller62094 жыл бұрын
Nr.3 you can also do: from operator import itemgetter sorted_data = sorted(data, key=itemgetter('age'))
@patloeber4 жыл бұрын
Yes thanks for the tip :)
@Mdroudian2 жыл бұрын
i like this
@plumberski88545 ай бұрын
Clear tips, like how you explain them, are simple and clear!
@davidvanleeuwen32743 жыл бұрын
Thanks a lot! The first minute already helps a lot.
@nebular-nerd Жыл бұрын
Some interesting tips, I'm just going through a reformat of a new script and this should help tidy and speed some operations.
@ekkyarmandi2 жыл бұрын
Nice tips. It speedup my code writing. Thanks, man.
@gauravrajput81092 жыл бұрын
I am so glad I found this channel.
@TheSuperUser4 жыл бұрын
Great video. Please make more of these quick tips for comparisons of "beginner" python code vs experienced developer idioms
@patloeber4 жыл бұрын
Thanks :)
@wintur285610 ай бұрын
Thanks for these tips! It's hard finding content outside beginner courses.
@PaulTheEldritchCat2 жыл бұрын
Nice tips, I'll save the video for later. Thanks!
@Kinos1413 жыл бұрын
Finally, how to do strings properly. I love using something like that in c#, and I'm glad it's on other languages like python.
@mei26542 жыл бұрын
2:59 you can preserve order with the help of sorted function example: my_list = [1, 2, 2, 3, 4, 5, 6, 7, 7 , 9, 8] sorted(set(my_list), key= lambda x: my_list.index(x)) >>> [1, 2, 3, 4, 5, 6, 7, 9, 8]
@0LoneTech Жыл бұрын
Fun fact: Dictionaries are now order preserving, so you can do the old trick of using a dict as a set and keep order without sorting. E.g. {k:None for k in [5,2,3,2,6,5,1]}.keys()
@thebuggser27523 жыл бұрын
Great collection of useful tips, presented very clearly and concisely. Thanks!!
@rushi73122 жыл бұрын
I'm a beginner -ish and knew about half to 2/3rd, but also learned a few good tricks :) Thanks
@akshitstenaa3 жыл бұрын
I am your fan now , thx a ton mate for all these tips.
@patloeber3 жыл бұрын
Awesome, thank you!
@akshitstenaa3 жыл бұрын
Please try adding videos on Scarpping, ML & analytics . 🙂
@srimanthmahadev82723 жыл бұрын
An alternative of TIP 10: if you have two dictionaries you can join them using | operator. d1={'one' : 1, 'two':2} d2={'three':3} d3=d1|d2 print(d3) output: {'one': 1, 'two': 2, 'three': 3}
@patloeber3 жыл бұрын
yep great tip!
@vishnuuvardhanreddy30103 жыл бұрын
Bro i am new to python I am very much interested to learn python please give me suggestion to develop my python basics to reach up to a professional level
@notbme27313 жыл бұрын
@@vishnuuvardhanreddy3010 KZbin and reddit are your best friends to learn anything
@ИванИваныч-н3у3 жыл бұрын
Not worked on all versions of python, just new.
@ИванИваныч-н3у3 жыл бұрын
What about dict update method?
@marcelomelo634911 ай бұрын
My tips: 1.Use map instead of for 2.Don't forget the walrus operator, just a details. 3.Don't use func(list[0], list[1]) use func(*list) 4.The tip 3 is also good for creating iterables in certain cases, [*list] for example 5.Don't iterate if you want new items for the list, use list.extend()
@marcelomelo634911 ай бұрын
What do you think? Do you have more?
@akira_asahi2 жыл бұрын
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@alankritverma183910 ай бұрын
one of the best python videos. Really useful
@DisSsha3 жыл бұрын
Hello, Thanks for those great tips !! Does someone knows which IDE he is using ?
@goldendovah76133 жыл бұрын
Looks like visual studio code.
@faithinverity85232 жыл бұрын
Superb [ ] of tips. Thank you!
@davidtalturejman9185 Жыл бұрын
Thanks man! Nice video!!
@rutanshudesai2 жыл бұрын
amazing tips, very very valuable. thank you for sharing.
@abdallahsalim47592 жыл бұрын
Thanks man, this was helpful
@MasterEhsan3695 ай бұрын
THANKS that was useful...
@fahnub2 жыл бұрын
bro this was super helpful. thanks for this.
@shababe22432 жыл бұрын
Excellent information,Thanks
@leesweets41102 жыл бұрын
Generators and dictionary merger were new to me and I can see being very useful. Are generators more costly in terms of time efficiency? Seems to me that calling it multiple times is less efficient than having a precomputed list.
@gudguy1a Жыл бұрын
Still very relevant content, thanks for having this.
@GaelGendre3 жыл бұрын
Dude this is great, thanks!
@patloeber3 жыл бұрын
happy to hear this :)
@datastako1562 жыл бұрын
very helpful. thank you!
@Kinos1413 жыл бұрын
I noticed that merge dictionaries doesn't merge into a new line, but more over writes the old on. I changed the name in the d2, and it overwrote the name in d1. I thought it would just create a new name in the dict. Is this the intended behavior?
@ИванИваныч-н3у3 жыл бұрын
Yes, the keys must be unique, otherwise it will be replaced.
@zacky78623 жыл бұрын
Could you please tell how to safely count or check the if the generators items are empty?
@Zephyr-tg9hu4 жыл бұрын
Awesome tips, thank you!
@patloeber4 жыл бұрын
Glad it's helpful!
@latt.qcd92213 жыл бұрын
The idea of list comprehensions was new to me, but I was curious if there was an option for dictionary comprehensions and, sure enough, there is! Was able to clean up a lot of my dictionary for loops. Thanks!
@mostafasadeqq2 жыл бұрын
what a legend , ty very much man
@changwei-zhe94063 жыл бұрын
thanks for the useful sharing!!!
@patloeber3 жыл бұрын
glad you like it!
@jomelsanpedro72713 жыл бұрын
thank you so much. keep it up you're the best.
@patloeber3 жыл бұрын
thank you!
@javohirorziqulov96443 жыл бұрын
only one word: amazing...
@patloeber3 жыл бұрын
thanks!
@akashgillella2 жыл бұрын
Wonderful tips. Every single one is pretty useful.
@gomathikreddy3503 жыл бұрын
Great content. Thank you for sharing ur knowledge. It'll help if the font sizes are larger for screen casts. I watch ur videos on an old android phone. 😐
@patloeber3 жыл бұрын
thank you for the feedback! I try to improve this on my newer videos
@gomathikreddy3503 жыл бұрын
Thank you. 😊🙏
@zacky78623 жыл бұрын
This is great. I'm always looking on better coding style. Could you tell which vs code theme that you are using? Thanks
@patloeber3 жыл бұрын
Yes, I think it's the Night Owl theme
@mmxo26312 жыл бұрын
literally watched for 1:03 seconds and i love the video. I'm a beginner btw. SUBBED!
@octobotdev2 жыл бұрын
Thanks for the tips, always great to listen to fellow Python devs!
@victorsuarez43332 жыл бұрын
Thank you, this video was very helpful!
@HiteshKumar-1784 жыл бұрын
Really admire your work! Nice work mate
@patloeber4 жыл бұрын
Thank you!
@alyssonmachado12543 жыл бұрын
Valuable tips! Thank you very much!
@sc0urge5613 жыл бұрын
One question though, are generators also faster than lists?
@patloeber3 жыл бұрын
no, the important point is that it requires less memory
@NavinKumar-tv9hg Жыл бұрын
Wonderful. Thank you!
@enzopestana6 ай бұрын
really helpful, thanks a lot
@manuelpardall86883 жыл бұрын
Very useful tips and tricks! Thank You
@patloeber3 жыл бұрын
glad it's helpful :)
@knowledgedaily11733 жыл бұрын
This is one of the best python related videos I have seen.
@patloeber3 жыл бұрын
thanks a lot!
@tincustefanlucian74953 жыл бұрын
Generators tip was quite a nice trick to know! So easy to be confounded with list generator.
@patloeber3 жыл бұрын
yep it's very handy sometimes :)
@onurkoc68692 жыл бұрын
You are Superman:) Thanks for all of sharing.
@abdulqadar95802 жыл бұрын
Please make complete playlist like these tips of python
@chuzhong12142 жыл бұрын
Is the enumerate function really that much better? Having trouble finding convincing arguments other than “it’s more pythonic”. Performance also seems to be better using range/len … presumably because you don’t have to generate a whole list of indices first but rather just fetch the size of the array itself.
@0LoneTech Жыл бұрын
enumerate creates (and usually unpacks) a tuple for each item, so it is quite plausible to have it operate slightly slower than a range iterator. range hasn't built the full list since Python 2 (back then the current range was known as xrange). You can also enumerate any iterable, not just sequences of known length. Mostly the difference does come down to clarity, and that's a pretty compelling argument IMHO. How long would it take you to recognize zip(itertools.count(), iterable) as the same function?
@petelogiudice82022 жыл бұрын
Very helpful in refactoring my brain to be more pythonic!
@MrGustavCR4 жыл бұрын
Another great video. Thanks for the amazing content.
@patloeber4 жыл бұрын
Glad you like it :)
@maxfondle67932 жыл бұрын
Thank you. Mind actually blown.
@bashvim2 жыл бұрын
What keyboard shortcut are you using run the python file in the Output tab below?
@paulosergioschlogl95508 ай бұрын
The {**d1, **d2} can be used with collections defaultdicts?
@jorgeluismongeblanco69332 жыл бұрын
For #1, I would prefer a list comprehension: data = [0 if e < 0 else e for e in data]
@albertog21964 жыл бұрын
Best python channel in YT
@patloeber4 жыл бұрын
Thank you :)
@krupaneshkrishnan92843 жыл бұрын
Great video, Thanks.
@eranzaksh Жыл бұрын
Thank you! Isn't enumerate slower then range(len())?
@azsxcvbnhjks3 жыл бұрын
the first tips give error if you try it. 'int' object does not support item assignment
@manojm90842 жыл бұрын
This is a very good video. Thank you very much , keep up the good work .
@Mangohawk1242 жыл бұрын
What idle do you use i.e what is used in the vedio ??
@travelchimps663710 ай бұрын
Great content and background music
@sig78133 жыл бұрын
Very cool. Learn from you a lot
@patloeber3 жыл бұрын
Glad to help
@TejasBangera4 жыл бұрын
Thank you, Subscribed to the channel
@patloeber4 жыл бұрын
Thanks!
@saitejam37692 жыл бұрын
Sir please post videos on nested loops and tips in nested loops
@castlecodersltd2 жыл бұрын
Very useful, thanks ☺
@MarioVegaTOAO3 жыл бұрын
Most excellent video!
@mohamedmzoughi82342 жыл бұрын
Very informative great job
@chakkarapaniv4 жыл бұрын
Hey, Excellent videos. The style is amazing! and more informative!. I am following you.
@patloeber4 жыл бұрын
Great, thank you!
@emilioschmidt21063 жыл бұрын
Why does the .join method not accept generators? Wouldn't that be a perfect use case as you only need the values of the list one at a time
@patloeber3 жыл бұрын
yeah it's only implemented for strings, but you could implement your own join method for generators
@mywebuniversity2 жыл бұрын
Excellent video, very precise and nicely done!
@pavin39492 жыл бұрын
What is the compiler r u using ?
@ssshukla263 жыл бұрын
Merge dictionaries.... Woahhhhh.... Oh my God... Thank you so much... That will make my life a bit easier....
@prashanthreddy19243 жыл бұрын
you made me a better programmer with this video. Please do more series of videos like this.
@patloeber3 жыл бұрын
glad to hear this!
4 жыл бұрын
Hey dude. Thanks for this video, it helped me a lot in my studies! What's the theme you're using? I found it really cool and couldn't find it on the marketplace
@patloeber4 жыл бұрын
It's the night owl theme. Have a look at my tutorial about my VS Code setup :)