20 Everyday Tips & Tricks in Python
Vložit
- čas přidán 4. 07. 2024
- How's it going everyone? Today we're going to be going over 20 everyday tips and tricks that you can use in your Python scripts!
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels
00:00 Learning Python made simple
00:05 Intro
0012: Variable swapping
01:10 Reversing iterables
01:45 Multiplying strings
02:40 One line conditions
03:28 Joining strings
04:32 Getting values
05:52 Getting & setting values
07:19 Counters
08:37 Specifying a start
09:37 Dictionary merging
10:23 Underscore formatting
11:58 Callable classes
13:32 Method chaining
15:07 Formatted list printing
16:06 Representation
17:17 Unpacking
18:37 Quick debugging
19:31 Rounding
20:38 String replacement
21:56 Max & min keys
25:01 End
"It's cool because there is Bob" 😂
21:40 - I would use regex here, as instead of spaces there might be some other separations + upper case problem would be solved as well
Yeah, 're' is amazing
Just wanted to point out that defining __ call __ on a class makes _instances_ of that class callable not the class itself. All classes are callable anyways since that's how you create new instances.
21:44
If you replace just " red" with " blue", the string " reduced" would still turn into " blueduced".
Also, the string "red" would be unchanged because it doesn't start with a space.
In that case we can use *re.sub*
No 15: overloading repr() is a good idea. You can also use "type(self).__name__" or self.__class___.__name__ instead of the explicit "Person" in the f-string.
23:50 you can also use a tuple as a key to achieve multilayer sorting such as min(names, key = lambda name: (name.lower().count('a'), name))
#13 "Bob, who's obviously named Jeff" - gets me every time... 🤣🤣🤣
Great video. My interest was peaked while watching.
Regarding default values for dictionaries, you should also have a look at the collections.defaultdict class which I find very useful. There you can specify a general default value that you get if the key doesn't exist. This is very useful e.g. if you want to count something.
Another alternative is subclassing dict and defining the __missing__ method. It has the bonus of providing the key to compute the default dynamically
splendid...keep up good work.
This is Gold!
As a corollary to multiplying strings and arrays, I overloaded / so that I could divide them as well. Take for instance "ababab"/"ab" would yield 3, and "bababa"/3 would yield "ba". You could probably make a video on showing an implementation of that. It would likely be better than mine.
Your content is very useful
Yeah another indently vid! :D
Great video
Using replace(' thing', ' other') doesn't work for words that start with thing (the same way replace('thing ', 'other ') doesn't work for words that end with thing (and if the character behind it is not a space, for exemple a period or a comma, it won't work either)
Included with the python std lib there is a module called 're' that allows you to find and replace using regex
Very nice 👍🙂
Thank you for this very useful video. Can I ask you what theme you use in Pycharm?
pretty sure he uses the default
Nice
What happens if one gets from the dictionary, "Bob" instead of getting "name?"
I use these tricks everyday
If one wants to comvine two dicrionaries a and b, then why not simply a + b?
13:21
... it looks quite confusing.
Haskell: Good luck!
what is the difference __str__ and __repr__
11:15 for those in a country that swaps the decimal and comma in numbers:
f'{big_number:_}'.replace('.', ',').replace('_', '.')
print(*_) gives a space-delimited row of names, not a list object.
😮
Ha ha ha.
He made python more simpler
I love python
33 sec ago was wild
🎉
i can't believe you typed "odd" with zero instead of capital 'o'... this is bothering me...
He wrote the numeral zero in the word "Odd" instead of the capital letter O. 😮
Poor Bob, being byte by like 20 small pythons... sheez...
Python is beautiful, but counter: Counter = Counter() is just not ZEN.
I know, right? Get yer dang Java outta my Python
I know right? Get yer dang Java outta my Python!
Why you have adverbs if you have sponsored video?
What do you mean? “An adverb is a word or an expression that generally modifies a verb, adjective, another adverb”.
@@Martin-deltayou’re kidding right? It’s too deadpan.
@@DrDeuteron lol no. I was genuinely confused. I just copied the Wikipedia entry for adverb. 🤷♀️
Lame... seen these "tips" 1_000_000 times before....
i like the pun here
really undurated!