10 Python Functions That Will Simplify Your Life

  Рет қаралды 59,049

Tech With Tim

Tech With Tim

Күн бұрын

Пікірлер: 103
@TechWithTim
@TechWithTim 2 ай бұрын
To learn programming and Python - check out Datacamp! 💻 Learn Python - datacamp.pxf.io/PyJ9WM 💻 Learn Programming - datacamp.pxf.io/9g4PrY
@fikunyinmiadebola5725
@fikunyinmiadebola5725 2 ай бұрын
Hello Tim, when are you going to get back to us on the live coaching opportunity. P.s. I am the Nigerian kid.
@TechWithTim
@TechWithTim 2 ай бұрын
@@fikunyinmiadebola5725 Hi, I am currenly reviewing applications as we speak
@gamingsama2
@gamingsama2 2 ай бұрын
Will you add Arabic translation to the course in the future ?
@fikunyinmiadebola5725
@fikunyinmiadebola5725 2 ай бұрын
@@TechWithTim Thanks for the reassurance
@DrDeuteron
@DrDeuteron 2 ай бұрын
the dataclass module also has astuple() and asdict() functions that are really useful when you're sending your data to another function (e.g., a plotter) that doesn't care about all the class structure. And the "field" function is great for defining what each attribute is. I use it on space craft telemetry, and you can attach ranges, alarm levels, units (ounce-inch or N-m, for example), and also LaTex r-strings for status plots. It saves soooooo much boiler plate code. Moreover, it puts all the information in static variables attached to the instance, not a module dictionary, or worse: run-time magic numbers .
@watchingwatches7863
@watchingwatches7863 2 ай бұрын
One super useful thing for me is named tuple from collections. This allows to get an information of an tuple by using a keyword instead of an number. This way you don't have to keep in mind which index saved what. Especially useful, when you haven't worked for some time on the project
@AvinashSingh-kl6oz
@AvinashSingh-kl6oz 2 ай бұрын
Rather than using the pprint module which does not work as good with nested lists and dictionaries, I prefer to write my own pprint function like this: import json def pprint(data: Dict[Any, Any]): print(json.dumps(data, indent=4)) This gives us a lot cleaner output
@kraig9
@kraig9 Ай бұрын
The default dict collection is actually really good for a factory pattern. If the class you're wanting isn't in the factory you could return a default class!
@RickGladwin
@RickGladwin 2 ай бұрын
`dataclass` seems like it serves a similar purpose to the `Record` class in Java (allowing for more data-oriented programming), but with slightly different built-in methods. It's interesting that `dataclass` isn't immutable by default though (you have to set `frozen=True`). Great video :)
@multigladiator384
@multigladiator384 2 ай бұрын
16:50 yes!!! decorators are great stuff. there are many many more in standard python. moreover, if you use modules like flask and stuff. you will also see this concept in java environment e.g if you use spring boot for you application server. Imagine you would have check, if the user sending an incoming request is legit, has certain roles, ...you can do this stuff with decorators (code defined in one place!) instead of duplicating code in the beginning of these endpoints
@ridwanray
@ridwanray 2 ай бұрын
Absolutely correct. I have something similar top 30.
@usamashami11
@usamashami11 2 ай бұрын
The variety of content you make says a lot about how much knowledge you have! ❤ I start feeling fomo how can i cover so much content 😅🥺
@ridwanray
@ridwanray 2 ай бұрын
Tim knows his stuff. I have a similar video for top 30.
@Andrumen01
@Andrumen01 Ай бұрын
3:38, never ever use "pickle" unless you are running in a safe and contained space (e.g., a remote Docker container). Since "pickle" loads python objects, it can be used to run malicious scripts! Try to find/create your own (safer!) serialization methods!
@Rickety3263
@Rickety3263 2 ай бұрын
7:31 or if its a set you can use “if “apple” in strings”
@ridwanray
@ridwanray 2 ай бұрын
Good job, Tim. I created something similar, but for top 30.
@multigladiator384
@multigladiator384 2 ай бұрын
1:55 i use the standard get method for this on dicts... You can pass the value as argument to the get-function, which will be returned, if the key does not exist, e.g false, empty strings..very useful in condition clauses /control structures and moreover in higher concepts (syntactic sugar ) like list- and dict comprehensions, where you can use if-structures as well. Imagine you want to list compehend some values from multiple dict elements, which are in a list and share the same key mapping to the desired value in each one... vals = [val["someKey"] for val in myDict if val.get("someKey",False)!=False] now imagine these val["someKey"] are strings and you do not want the empty strings in your final vals list: vals = [val["someKey"] for val in myDict if val.get("someKey",'').strip()!=''] Of course, you can first cast them to str or whatever, if the type is any because of the nature of this dynamically typed programming language
@DrDeuteron
@DrDeuteron 2 ай бұрын
"is not False" "!= False" is unpythonic, But since the default is None: val.get("someKey") is not None is preferred, unless None is an expected value ofc.
@multigladiator384
@multigladiator384 2 ай бұрын
@@DrDeuteron You are correct
@DrDeuteron
@DrDeuteron 2 ай бұрын
@@multigladiator384 Other languages! 🤢🤢🤮
@mint9121
@mint9121 2 ай бұрын
Thanks for the video. My fav was counter()!
@ridwanray
@ridwanray 2 ай бұрын
I created something similar, but for top 30
@peterkahofficial
@peterkahofficial 2 ай бұрын
Hey Tim, thanks for the video! Can you make a video about the new FastHTML framework? It looks really promising!
@multigladiator384
@multigladiator384 2 ай бұрын
14:20 yea man itertools, now we get to the stuff I am talking about in my previous comment
@softwareengineer8923
@softwareengineer8923 2 ай бұрын
Useful content as usual, thanks 👍
@eboyd53
@eboyd53 2 ай бұрын
Q: you stated "wb" and "rb" is "write bytes" and "read bytes" in my many years of data analysis I always stated "binary" where you state "bytes"; the question is where did you find that it means "bytes"?
@Borszczuk
@Borszczuk 2 ай бұрын
Correct, "b" stands for binary, not bytes. He was just wrong (or never read the manual :-)
@neckbro
@neckbro 2 ай бұрын
You can call APIs -- Awesome programming interface. It doesn't matter how you call it as long as you know what it is doing and how to work with it.
@Borszczuk
@Borszczuk 2 ай бұрын
@@neckbro This is not a "poem analysis class" where you can have as many interpretations as pupils in the class. And no, you cannot call it as you like, esp. if you teach others incorrectly.
@malsi1504
@malsi1504 2 ай бұрын
​@@Borszczuk If I learned API stands for awesome pizza inspector, which is the guy who defined rules that enable applications to communicate, and it must be used to request data or services. if I learn that a GUI is a gorgeous unicorn interface which is a type of user interface that uses visual elements to interact with a computer, and it uses windows, icons, menus, and pointers to interact with the user, if I recall that an IP Address is an incredible pizza address which is a unique numerical label assigned to each device connected to a computer network, and it must be unique and follow a specific format ... You might notice that I have completely incorrect descriptions of terms. But in programming... Notice how the parts that are correct are the only parts that NEED to be. If you have these wrong you create programming errors. It's better not to be wrong about what you teach. But it's like teaching a historical artifact. You teach what it was, what it meant, how it was used, when it was used. But imagine the label was completely wrong. That's most things we learn in history. Often we don't correctly know what the label was when it was used. Sometimes we only know if it's existence thru translation. Sometimes the labels or language used is so different from the one I'm teaching in, their label uses sounds and meanings that we don't have in English, so instead we will probably give it a romanized label and forever forward refer to that thing with that label. Completely changing the original "name" of the object. The fact that it simply doesn't change why it was used when it was used how it wasrd how old is it what does that mean for the advancement of that culture, etc.... none of that important stuff changes. We just have the label wrong.
@chrisogonas
@chrisogonas 2 ай бұрын
Awesome! Thanks for sharing.
@multigladiator384
@multigladiator384 2 ай бұрын
Good video my man
@jlawless1984
@jlawless1984 2 ай бұрын
Good stuff, thank you.
@cloudzero2049
@cloudzero2049 2 ай бұрын
Thanks for the video. :)
@Jody_Halliday
@Jody_Halliday 2 ай бұрын
Great job, thank you! 🧡
@DrDeuteron
@DrDeuteron 2 ай бұрын
I don't think enumerate returns an index, as evidenced by the "start=" keyword..rather it provides a count. Useful for managing matplotlib subplots, for example.
@ridwanray
@ridwanray 2 ай бұрын
It does return index.
@dimox115x9
@dimox115x9 2 ай бұрын
Nice video, thank you very much :)
@diegomerino9939
@diegomerino9939 Ай бұрын
Many thanks for your videos. I would like to know the name of the font you are using.
@ded_linux
@ded_linux 2 ай бұрын
❤❤❤❤ cool funcs thanks Tim
@kapibara2440
@kapibara2440 2 ай бұрын
Very useful!
@mlguy8376
@mlguy8376 2 ай бұрын
Try unpacking a pickled class with out a class definition available (for whatever reason)
@nephxio
@nephxio 2 ай бұрын
Would it be accurate to think of a dataclass as like a struct with a little extra functionality from other languages like C++?
@hackedbyBLAGH
@hackedbyBLAGH 2 ай бұрын
Thank you
@ridwanray
@ridwanray 2 ай бұрын
@multigladiator384
@multigladiator384 2 ай бұрын
12:28 yes, list- and dict comprehension are great syntactic sugar. but be aware, that there are cases where a simple for loop will outperform it, instead of doing multiple (lets' say 4) list/dict comprehensions on one and the same list/dict object you can do all the operations in one explicit for loop (1n vs 4n speaking from complexity pov - yes this in in theorie stil in the scope of just n but in reality it can matter if there are thousands of elements in the underlying list, dict)
@DrDeuteron
@DrDeuteron 2 ай бұрын
performance over clarity? wt_?
@multigladiator384
@multigladiator384 2 ай бұрын
@@DrDeuteron I have to disagree here! In many cases, it is important! You may also put it as Usability/User-Experience over code-clarity? Every half-decent (classically taught) programmer will be able to read a for loop.. Thus, I do not see the clarity enhancement here really but the performance advantages. As I said: If you have lists with thousands of objects or whatever, it will be a difference of multiple seconds until the server responds. In most cases of applications servers you have customers/users, that want a relatively "fast" experience and not wait multiple seconds because backend pythonists like to use comprehensions everywhere..
@multigladiator384
@multigladiator384 2 ай бұрын
@@DrDeuteron In that regards I do not give a fuck if you call my code "pythonic". It is performant and user-friendly and still readable for every half-decent programmer... This "pythonic" shit is most of the time ideological and not applicable in reality where you have a webapplication, with thousands of users, that do not want to wait 5 seconds on every third request or what
@multigladiator384
@multigladiator384 2 ай бұрын
@@DrDeuteron For the context: I work in a data warehouse and build analysis tools, often big amounts of data are queried and this "pythonic" way takes way moooore time compared to a simple for loop over the data
@multigladiator384
@multigladiator384 2 ай бұрын
And me personally would use Spring Boot instead of flask but it is how it is and I am glad to have ajob :D
@selvanm2872
@selvanm2872 2 ай бұрын
hai i from india in tamilnadu
@Acanis87
@Acanis87 Ай бұрын
pickle, hmmm... Used that to store cookies but it might be way more useful than I thought... Is it a good practice to save and load ui settings with that m I have a Config class that stores everything and iam writing settings.json files so far. I could just use pickle and spare a lot of time, huh?!
@Beanbag59
@Beanbag59 2 ай бұрын
I’m a year into coding I can make small projects but like I wanna make really complex things what does chat or Tim recommend
@gurpreetchahal
@gurpreetchahal 2 ай бұрын
I want your advice Sir i am a QA engineer manual and automation, in future there will be no job for QA , should i switch to Developer? please help i am confused
@DrDeuteron
@DrDeuteron 2 ай бұрын
idk, I make satellites, and we got QA all up in our business,
@RickGladwin
@RickGladwin 2 ай бұрын
I think there will still be a use for QA in the future, though QA will have more and more to do with testing things that can't be automated, that require a human's evaluation. If there is a requirement in the spec that says "this button should be visible if the user is logged in", that's something that can be automated and doesn't belong to QA. If there is a requirement that says "a user should be easily able to find their transaction history", that's something that can't be automated and needs a QA tester. If you are worried, I would recommend looking for those parts of QA that are in increasing demand, like evaluating user interfaces based on visual impairments and other disabilities, and always increasing your skills and expertise. Good luck!
@multigladiator384
@multigladiator384 2 ай бұрын
8:02 "all" function should be mentioned in this context, too. "any" and "all" are really useful.
@multigladiator384
@multigladiator384 2 ай бұрын
8:35 okay, you just mentioned "all" function .. I am sorry i have commented too early here..
@DrDeuteron
@DrDeuteron 2 ай бұрын
is any()'s evaluation short-circuited?
@multigladiator384
@multigladiator384 2 ай бұрын
@@DrDeuteron the first "True" will end the logical OR ("any" function) since the whole expression evaluates to True. No need for further evaluations in contrast to the logical AND ("all" function), which requires each single expression to be True so the complete expression evaluates to True. You know that
@ridwanray
@ridwanray 2 ай бұрын
Yes. I have for top 30
@rydmerlin
@rydmerlin 2 ай бұрын
Try pprint with your defauldict
@ridwanray
@ridwanray 2 ай бұрын
@riccardomenoli5185
@riccardomenoli5185 2 ай бұрын
I'm wondering how dataclass works with pydantic. They have the same syntax
@DrDeuteron
@DrDeuteron 2 ай бұрын
I'm stuck at 3.8 for security, and dataclass is available.
@toancdu
@toancdu 2 ай бұрын
I have an error when run program, when I input the Video, then choose folder for download, but it shows:" HTTP error 400: bad request", Please help me why?
@marcinziajkowski3870
@marcinziajkowski3870 2 ай бұрын
4:42 what if class is not defined before load object from pickle file ?
@marcincuprjak1005
@marcincuprjak1005 2 ай бұрын
not sure if that appeared in the comments, but there is one tricky case: `all` called with the empty iterable returns True, which may be unexpected: `all([]) -> True`
@itznukeey
@itznukeey Ай бұрын
Note that pickle is unsafe - do not load any pickles you don't trust because they can execute arbitrary code
@marjoncajocon4219
@marjoncajocon4219 2 ай бұрын
I thought dataclasses is from python 3.0, im using python 3.7 and dataclasses is available by default
@qwerty11111122
@qwerty11111122 2 ай бұрын
Chain is orthogonal to zip?
@marcinziajkowski3870
@marcinziajkowski3870 2 ай бұрын
3:24 {3,2,1} ? Why not {1,1,1} ?
@alucard555
@alucard555 2 ай бұрын
Can anyone help me with Data structures, where do I start
@omniu
@omniu Ай бұрын
What is your theme?
@Larimuss
@Larimuss 2 ай бұрын
Can you please do a new tutorial with more advanced python? 😅😊
@ridwanray
@ridwanray 2 ай бұрын
Sure. Project based
@ethiogazeta
@ethiogazeta 2 ай бұрын
1St
@HRamazanoVv
@HRamazanoVv 2 ай бұрын
1 min ago is 😛😛😛😛😛😛😛
@neckbro
@neckbro 2 ай бұрын
Thumps down again for this video! Why are you not sharing the code or a notebook so we can experiment ourselves instead of trying to write everything from start? That means you are just after few more clicks on your channel or feeling to important to bother with it, or most probably both.
@TechWithTim
@TechWithTim 2 ай бұрын
Sorry I didn’t know you wanted that! Next time !
@colton3507
@colton3507 2 ай бұрын
Lol don't listen to neckbros
@neckbro
@neckbro 2 ай бұрын
@@TechWithTim Yeah, it doesn't have to be pretty, even a dump on a txt file would work
@neckbro
@neckbro 2 ай бұрын
@@colton3507 My comment is more useful to him than 100x "thank you so much" comments. It helps to practice how to deal with criticism even when famous
@DrDeuteron
@DrDeuteron 2 ай бұрын
bro: you gotta do the work yourself to learn it. No one got strong being spoon fed pushed peas.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 195 М.
Python Generators Explained
28:37
Tech With Tim
Рет қаралды 157 М.
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 55 МЛН
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 86 МЛН
Sigma baby, you've conquered soap! 😲😮‍💨 LeoNata family #shorts
00:37
Python Data Classes Are AMAZING! Here's Why
16:11
Tech With Tim
Рет қаралды 83 М.
The New Python 3.13 Is FINALLY Here!
20:39
ArjanCodes
Рет қаралды 79 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 117 М.
15 Python Libraries You Can’t Miss
22:31
ArjanCodes
Рет қаралды 49 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,2 МЛН
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 154 М.
How To Write Better Functions In Python
14:17
Indently
Рет қаралды 43 М.
Generative AI in a Nutshell - how to survive and thrive in the age of AI
17:57
Data Analysis with Python for Excel Users - Full Course
3:57:46
freeCodeCamp.org
Рет қаралды 2,8 МЛН
5 Good Python Habits
17:35
Indently
Рет қаралды 583 М.
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 55 МЛН