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
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
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.
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.
Nr.3 you can also do: from operator import itemgetter sorted_data = sorted(data, key=itemgetter('age'))
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]
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!
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.
I almost don't know any python, but I was able to comprehend 80% of the content. Amazing simple explanation. Thanks.
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
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}
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
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.
Great video. Please make more of these quick tips for comparisons of "beginner" python code vs experienced developer idioms
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.
I love how you explain with simplicity. Great content.
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.
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.
What keyboard shortcut are you using run the python file in the Output tab below?
@patloeber